15第十四周项目一——小玩文件
来源:互联网 发布:淘宝客服简历模板 编辑:程序博客网 时间:2024/03/29 14:45
/*
* Copyright (c) 2014, 烟台大学计算机学院
* All rights reserved.
* 文件名称:test.cpp
* 作 者:李晓凯
* 完成日期:2015年 6 月 7 日
* 版 本 号:v1.0
*
* 问题描述:完成程序,使其能统计abc.txt文件的字符个数
* 输入描述:无
* 程序输出:字符的个数
*/
(1)
#include <iostream>#include <cstdlib>#include _____________ // (1)using namespace std;int main(){ fstream file; file.open("abc.txt", _________); // (2) if(!file) { cout<<"abc.txt can’t open."<<endl; exit(1); } char ch; int i=0; while( _____________) // (3) { file.get(ch); _____________; // (4) } cout<<"Character: "<<i<<endl; file._____________;// (5) return 0;}答案:
(1)fstream
(2)ios::in
(3)!file.eof()
(4)close()
(2)
#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;}
(1)ios::in
(2)ios::out
(3)!infile.eof()
(4)getline(buf,80)
(5)i++
(3)用键盘输入文件名, 统计输出文件中每个字母,数字的个数
#include <iostream>#include <cstdlib>#include <fstream>using namespace std;int main(){ fstream outfile,infile; infile.open("aboutapp.txt",ios::in); // (1) if(!infile) { cout<<"Can’t open the file."<<endl; abort(); } char ch; int n=0,m=0; while(!infile.eof()) // (3) { infile.get(ch); if(ch>='a'&&ch<='z'||ch>='A'&&ch<='Z') n++; if(ch>='0'&&ch<='9') m++; } cout<<"字母:"<<n<<endl<<"数字:"<<m<<endl; infile.close(); outfile.close(); return 0;}
0 0
- 15第十四周项目一——小玩文件
- 第十四周项目一——小玩文件(1)
- 第十四周项目一:小玩文件
- 第十四周项目一--小玩文件
- 第十四周 项目一 小玩文件
- 第十四周项目一: 小玩文件
- 第十四周 项目一 小玩文件
- 第十四周项目一 小玩文件
- 第十四周项目一——小玩文件(2)
- 第十四周项目一——小玩文件(1)
- 第十四周项目一——小玩文件(2)
- 第十四周 项目一:小玩文件(1)
- 第十四周 项目一:小玩文件(2)
- 第十四周 项目一(3):小玩文件
- 第十四周项目一--小玩文件之填空
- 第十四周 项目一--小玩文件(1)
- 第十四周项目一之小玩文件
- 第十四周 项目一 小玩文件(1)
- shell学习第二天
- 第十三周项目三-立体类族共有的抽象类
- mac下mysql
- 管金生首次公开谈327事件
- [推荐视频教程]-[Java][传智播客 俄罗斯方法游戏开发 视频教程][avi]
- 15第十四周项目一——小玩文件
- Introduction to RTP Proxy (1)
- Android 优化电池使用时间 ——监控电池电量和充电状态
- 新建了CSDN博客,希望记录我的android学习历程
- android 选择图片 剪裁 拍照 兼容所有版本的代码
- java动态代理
- POJ 1700----Crossing River(过桥问题)
- 初识七层
- POJ1129 Channel Allocation