文本文件读写(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; }
相关文章推荐
- Java中的流与文件:文本的输入与输出
- C例程:文件读写 拷贝 标准输入输出等
- 使用XML文件输入和输出和YAML文件 目标 你会发现以下问题的答案: 如何打印和阅读文本条目文件和OpenCV使用YAML或XML文件? 如何为OpenCV做同样的数据结构?
- Java的输入输出与文件读写(一)
- 你好,C++(5)如何输出数据到屏幕、从屏幕输入数据与读写文件?
- Perl语言入门(第五版) 读书笔记(二)---输入与输出、文件读写
- (转载)你好,C++(5)如何输出数据到屏幕、从屏幕输入数据与读写文件?
- java基础-输入输出流-大文本文件读取及写入另一文本-----(此程序print部分有bug,输出不正常,原因琢磨不清了。。。)
- c程序设计语言_习题7-6_对比两个输入文本文件_输出它们不同的第一行_并且要记录行号
- 使用基本字节输入流,字节输出流一次读写一个字节来复制文本 文件
- Java 文件统计:编写程序,统计英文文本文件中的字符数目和单词数目。程序运行时,输入要统计的文件的名称,程序处理后输出字符数目和单词数目
- MyEclipse------文件字符输入,输出流读写信息
- Android读写文件基于Java的文件输入输出流
- 文件的输入输出(举例,文本文件复制) C 语言
- R:读写文件(输入与输出)
- C primer plus第13章(文件输入/输出)习题
- java输入输出到文件
- 一起学Shell之(六)输入、输出、文件与命令执行 推荐
- JAVA输入/输出流程序例题(文件和目录、字节流、字符流)
- C++中的文件输入/输出