Counting the number of lines in a file

Jun 3, 2013 at 7:21pm
Hello, I was trying to make a function that would return how many lines are in a certain file. I was looking at http://www.cplusplus.com/reference/cstdio/feof/
which talks about how to count how many characters are in a text file. I just want the number of lines with in a file. Can anyone help me?
Last edited on Jun 3, 2013 at 7:36pm
Jun 3, 2013 at 7:34pm
While std::getline succeeds, add to the line count?
Jun 4, 2013 at 12:59am
in a linear way, if your data is a specific fixed size per line then you count the number of chars (bytes) then increment if you reach the line length you need. Thats the best way I can think to do it. Or you could use a line terminator character if its a text file and check for that char, but that would waste space.
Topic archived. No new replies allowed.