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

来源:互联网 发布:手机淘宝查号网址 编辑:程序博客网 时间:2024/05/22 00:14

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

阅读全文
0 0
原创粉丝点击