ifstream inFile;
inFile.open(filename); //open the input file
stringstream strStream;
strStream << inFile.rdbuf(); //read the file
string str = strStream.str(); //str holds the content of the file
我正在使用此代碼從文件中讀取。我需要獲得該文件的行數。有沒有第二次閱讀文件的方法嗎?C++ fileIO行數
[C++獲取總文件行號(的可能的複製http://stackoverflow.com/questions/19140148/c-get-total -file-line-number) – rbaleksandar