您的位置:首页 > 其它

第十六周项目1-(1)-小玩文件

2016-06-12 13:12 288 查看
/*copyright(c)2016.烟台大学计算机学院
* All rights reserved,
* 文件名称:text.Cpp
* 作者:刘涛
* 完成日期:2016年6月11日
* 版本号:vc++6.0
* 问题描述:统计文本文件abc.txt中的字符个数,请填空将程序补充完整。
*/

#include <iostream>
#include <cstdlib>
#include <fstream> // (1)
using namespace std;
int main()
{
fstream file;
file.open("abc.txt", ios::in); // (2)
if(!file)
{
cout<<"abc.txt can’t open."<<endl;
exit(1);
}
char ch;
int i=0;
while(file.get(ch)) // (3)
{
++i; // (4)
}
cout<<"Character: "<<i<<endl;
file.close();// (5)
return 0;
}

运行结果:



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