我不能读书出文件内容,是不是哪里没搞好?用outfile和infile进行操作.
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
main()
{
ofstream outfile( "out_file" );
ifstream infile( "in_file" );
if(!infile)
{
cerr<<"error,the in_file can't read"<<endl;
return -1;
}
if(!outfile)
{
cerr<<"error,the out_file can't write"<<endl;
return -2;
}
string str;
while(infile>>str)
outfile<<str<<' '<<endl;
return 0;
}
文件"out_file和in_file都建立在当前目录下