从文件读入数据&向文件输出
#include <fstream>
#include <iostream>
using namespace std;
int main()
{
ifstream fileIn("C:\\Users\\shiwei\\Desktop\\test.txt");
ofstream fileOut("C:\\Users\\shiwei\\Desktop\\testOut.txt");
int temp;
while (fileIn >> temp) {
cout << temp << " ";
fileOut << temp << endl;
}
return 0;
}
#include <fstream>
#include <iostream>
using namespace std;
int main()
{
ifstream fileIn;
fileIn.open("C:\\Users\\shiwei\\Desktop\\test.txt");
ofstream fileOut;
fileOut.open("C:\\Users\\shiwei\\Desktop\\testOut.txt",ofstream::ate);
int temp;
while (fileIn >> temp) {
cout << temp << " ";
fileOut << temp << endl;
}
fileIn.close();
fileOut.close();
return 0;
}