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