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;
}


posted on 2013-08-16 19:21  bbsno  阅读(208)  评论(0编辑  收藏  举报

导航