C++ 读取一个文件时,统计文件中的换行符应该怎么判断?

如题所述

getline每次读取一行字符,也就是遇到“\n"就截断,所以你就打开文件不断用getline读文件,直到最后,然后计数读了多少个getline
int count=0;
string temp;
ifstream input;
input.open ("your file");
while ( input.good() && !input.eof() ) {
getline (input,temp);
count++;

}
cout << count;
温馨提示:答案为网友推荐,仅供参考
相似回答