How to get the line number from a file in C++?

后端 未结 4 1423
借酒劲吻你
借酒劲吻你 2021-02-02 01:15

What would be the best way to get the line number of the current line in a file that I have opened with a ifstream? So I am reading in the data and I need to store

4条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-02 01:36

    Use std::getline to read each line in one by one. Keep an integer indicating the number of lines you have read: initialize it to zero and each time you call std::getline and it succeeds, increment it.

提交回复
热议问题