C++文件輸入輸出小例子

#include <fstream>
#include <string>
#include <iostream>
using namespace std;

int main()
{
	ifstream infile;
	ofstream outfile;
	string str;
	infile.open("in.txt");
	outfile.open("out.txt");
	if (!infile)
	{
		cerr<<"error:unable to open input file:"
			<<infile<<endl;
		return -1;
	}
	while(infile>>str)
		outfile<<str<<endl;
	infile.close();
	outfile.close();
	return 0;
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章