#include <iostream>
#include <fstream>
using namespace std;
int main()
{
//创建输入字符流和输出字符流对象
ifstream in("E:\\data_in.txt");
ofstream out("E:\\data_out.txt");
if(!in.is_open()) //没有打开字符流对象就输出错误信息
cout << "Open file failure1" << endl;
if(!out.is_open())
cout << "Open file failure2" << endl;
int u, v, w;
while(!in.eof()) //没有到达输入文件的结尾
{
in >> u >> v >> w;
cout << u << " " << v << " " << w << endl;
out << u << "--" << v << " " << w << endl; //输出到文件中
}
in.close(); //关闭字符流对象
out.close();
return 0;
}
c++的文件读写操作
最新推荐文章于 2024-07-22 00:07:08 发布