阅读(2078)
赞(0)
C++ 文件输出
2016-02-24 15:08:27 更新
将输出发送到文件的方法与处理输入类似。例如,我们可以修改前面的程序以实现将一个文件逐行复制到另一个文件的功能。
ifstream infile ("input-file");
ofstream outfile ("output-file");
if (infile.good() == false || outfile.good() == false) {
cout << "Unable to open one of the files." << endl;
exit (1);
}
while (true) {
getline (infile, line);
if (infile.eof()) break;
outfile << line << endl;
}
← C++ 文件输入