#include <fstream>
#include "iostream.h"
#include <string>
using std::string;
using std::ofstream;
using std::ifstream;
int main()
{
ofstream outfile( "c:/out_file.txt" );
ifstream infile( "c:/in_file.txt" );
if( !outfile ){
cerr << "error: unable to open output file!/n" ;
return -1;
}
if( !infile ){
cerr << "error: unable to open input file!/n" ;
return -1;
}
string word;
while ( infile >> word )
outfile <<word << ;
return 0;
}
建立文本文件in_file.txt, 并写入“hello world!”
运行程序
打开out_file.txt
文件里已被写入“hello world!"。
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/smstone/archive/2006/04/13/661363.aspx