您的位置:首页 > 其它

文本文件读写(1.5.1 文件输入和输出)?

2013-01-31 14:33 309 查看
从一个名为in_file 的文本文件中读取单词然后把每个词写到一个名为out_file 的输出文件中并且每个词之间用空格分开。

我认为下面的程序不完整。

#include <iostream>
#include <fstream>
#include <string>
using namespace std;

int main()
{
ofstream outfile( "out_file.txt" );
ifstream infile( "in_file.txt" );
if ( ! infile ) {
cerr << "error: unable to open input file!\n";
return -1;
}
if ( ! outfile ) {
cerr << "error: unable to open output file!\n";
return -2;
}
string word;
while ( infile >> word )
outfile << word << ' ';

return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐