第十四周项目1 - 小玩文件(2)
2015-06-04 15:55
369 查看
(2)下面程序的功能是将文本文件abc.txt中的所有行加上行号后写到newabc.txt文件中,请填空将程序补充完整。
[cpp] view
plaincopyprint?
#include <iostream>
#include <cstdlib>
#include <fstream>
using namespace std;
int main()
{
fstream outfile,infile;
infile.open("abc.txt",_________); // (1)
if(!infile) {
cout<<"Can’t open the file."<<endl;
abort();
}
outfile.open("newabc.txt",______);//(2)
if(!outfile) {
cout<<"Can’t open the file."<<endl;
abort();
}
char buf[80];
int i=1;
while(____________) // (3)
{
infile.____________; // (4)
outfile<<________<<": "<<buf<<endl; //(5)
}
infile.close();
outfile.close();
return 0;
}
填充如下:
尼玛我觉得好像哪里不对。。。newabc里面肿么800000+行
图片:
[cpp] view
plaincopyprint?
#include <iostream>
#include <cstdlib>
#include <fstream>
using namespace std;
int main()
{
fstream outfile,infile;
infile.open("abc.txt",_________); // (1)
if(!infile) {
cout<<"Can’t open the file."<<endl;
abort();
}
outfile.open("newabc.txt",______);//(2)
if(!outfile) {
cout<<"Can’t open the file."<<endl;
abort();
}
char buf[80];
int i=1;
while(____________) // (3)
{
infile.____________; // (4)
outfile<<________<<": "<<buf<<endl; //(5)
}
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::out); // (1) if(!infile) { cout<<"Can’t open the file."<<endl; abort(); } outfile.open("newabc.txt",ios::out);//(2) if(!outfile) { cout<<"Can’t open the file."<<endl; abort(); } char buf[80]; int i=1; while(!outfile.eof()) // (3) { infile.getline(buf,80); // (4) outfile<<i++<<": "<<buf<<endl; //(5) } infile.close(); outfile.close(); return 0; }心得:
尼玛我觉得好像哪里不对。。。newabc里面肿么800000+行
图片:
相关文章推荐
- C# tostring 格式化输出
- 第二章 Spring MVC入门
- 02-线性结构2. 一元多项式求导 (25)
- 安装sqlserver 遇到服务操作系统与安装文件语言环境不一致问题
- Caffe 代码解析-convert_imageset
- JS事件委托
- Asp.net中web.config配置文件详解
- js基础----数组
- Online DDL工具的安装与使用
- Zookeeper中的FastLeaderElection选举算法简述
- DOM操作通过类名获取元素
- Linux中rename命令的用法
- java学习
- c++函数
- [D3] 9. Scatter Plot
- Android Matrix理论与应用详解
- 单向链表
- hbase行键过滤器RowFilter
- winform 遍历窗体中所有用户控件中的textbox 然后赋为空值
- 区块轮播