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

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

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

7条回答
  •  忘掉有多难
    2020-12-02 16:35

    How about this :-

      std::ifstream inFile("file"); 
      std::count(std::istreambuf_iterator(inFile), 
                 std::istreambuf_iterator(), '\n');
    

提交回复
热议问题