第十六周项目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; }
运行结果:
相关文章推荐
- Node.js之Express四
- php和C#的yield实现对比
- Linux中find常见用法示例
- OpenStack Liberty High Availability 概述和指导-第二部分
- Binary Search Tree Iterator
- poj2186 Popular Cows 题解——S.B.S.
- 进度条--第十五周
- C语言程序可以没有main函数
- QT 学习记录:渐变-QLinearGradient,QRadialGradient,QConicalGradient)
- Oracle 的安装与配置
- C# 位域[flags]
- AcceptEx WSAAccept accept
- python列表详解
- UVa 12118 nspector's Dilemma (构造+DFS+欧拉回路)
- Warning: Attempt to present A on B whose view is not in the window hierarchy!
- linux中断简介
- poj 1179 Polygon(化环为直+区间dp)
- 《软件工程》第十五周学习进度
- Android病毒查杀原理
- 欢迎使用CSDN-markdown编辑器