6.10 文件转移
2015-06-10 08:57
141 查看
下面程序的功能是将文本文件abc.txt中的所有行加上行号后写到newabc.txt文件中,请填空将程序补充完整。
#include <iostream>
#include <cstdlib>
#include <fstream>
using namespace std;
int main()
{
fstream outfile,infile;
infile.open("abc.txt",ios::in);
if(!infile) {
cout<<"Can’t open the file."<<endl;
abort();
}
outfile.open("newabc.txt",ios::out );
if(!outfile) {
cout<<"Can’t open the file."<<endl;
abort();
}
char buf[80];
int i=1;
while(!infile.eof())
{
infile.getline(buf, 80);
outfile<<++i<<": "<<buf<<endl;
}
infile.close();
outfile.close();
return 0;
}
#include <iostream>
#include <cstdlib>
#include <fstream>
using namespace std;
int main()
{
fstream outfile,infile;
infile.open("abc.txt",ios::in);
if(!infile) {
cout<<"Can’t open the file."<<endl;
abort();
}
outfile.open("newabc.txt",ios::out );
if(!outfile) {
cout<<"Can’t open the file."<<endl;
abort();
}
char buf[80];
int i=1;
while(!infile.eof())
{
infile.getline(buf, 80);
outfile<<++i<<": "<<buf<<endl;
}
infile.close();
outfile.close();
return 0;
}
相关文章推荐
- 面试集锦
- Hadoop 错误归档库
- android Graphics:区域(Region)
- 第14程序阅读 例6.2
- c/C++内存分配
- 第十三周项目三 立体族类的纯虚函数
- 认识自己——要用心感受世界
- 浅析JavaScript动画
- 第十四周程序阅读(2)
- 第十四周程序阅读——例六
- 第13周-阅读项目2-有关参数的get函数
- http://www.softreg.com.cn/共享软件中心。
- OpenWrt系统安全改进<五> --- Web 访问权限分级
- .Net 转战 Android 4.4 日常笔记(9)--常用组件的使用方法[附源码]
- 第十四周项目1-小玩文件(2)
- 使用NSURLConnection获得网络数据
- [UOJ 118][UOJ Round #8]赴京赶考
- ios/oc中的结构体 与字符串互转
- .Net 转战 Android 4.4 日常笔记(8)--常见事件响应及实现方式
- 期待已久的2012年度最佳jQuery插件揭晓