文件-写文件

#include "stdafx.h"
#include <fstream>
#include <string>
#include <iostream>
int _tmain(int argc, _TCHAR* argv[])
{
	std::string filename = "outfile.txt" ;
	std::ofstream outfile(filename.c_str());

	if(!outfile)
	{
		std::cout<<"Open file '"<<filename<<"' failed"<<std::endl;
	}
	else
	{
		outfile<<"kevin"<<" "<<"26"<<" "<<"175"<<"\n";
		outfile<<"Lucy"<<" "<<"22"<<" "<<"162"<<"\n";
		outfile<<"John"<<" "<<"26"<<" "<<"176"<<"\n";
		outfile<<"Peter"<<" "<<"23"<<" "<<"177"<<"\n";
	}
	return 0;
}


写入outfile.txt文件内容:
John 25 172
Lucia 22 165
Jack 29 179
Mark 35 174

你可能感兴趣的:(C++,c,C#)