您的位置:首页 > 编程语言 > C语言/C++

cpp: 统计文本文件中的字符数量

2017-12-03 12:53 302 查看
c++
中打开文本文件,读取字符数量是一个比较简单的操作。

#include <iostream>
#include <fstream>

using namespace std;

int main() {

fstream fin;
fin.open("dcb.txt");

char ch;
int counter = 0;
while (fin && fin.get(ch)) {
cout << ch;
counter++;
}
fin.close();

cout << "\ntotal litters of this file:" << counter << endl;

}


输出

hello world

who you are?

total litters of this file:24
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐