#include <iostream>
#include <string>
#include <cstdlib>
#include <fstream>
int main()
{
using namespace std;
ifstream inStream;
ofstream outStream;
inStream.open("infile.dat");
if (inStream.fail()) {
cout << "打开文件 infile.dat 失败" << endl;
exit(1);
}
outStream.open("outfile.dat");
if (outStream.fail()) {
cout << "打开文件 outfile.dat 失败" << endl;
exit(1);
}
int first, second, thrid;
inStream >> first >> second >> thrid;
outStream << first << endl << second << endl << thrid << endl;
inStream.close();
outStream.close();
return 0;
}
输出:
infile.dat
outfile.dat