How to count lines of a file in C++?

后端 未结 7 1171
故里飘歌
故里飘歌 2020-12-02 15:53

How can I count lines using the standard classes, fstream and ifstream?

7条回答
  •  清歌不尽
    2020-12-02 16:45

    int aNumOfLines = 0;
    ifstream aInputFile(iFileName); 
    
    string aLineStr;
    while (getline(aInputFile, aLineStr))
    {
        if (!aLineStr.empty())
            aNumOfLines++;
    }
    
    return aNumOfLines;
    

提交回复
热议问题