欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

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

程序员文章站 2022-03-02 12:47:24
...
#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;
}