1

title says it all.

I have a file where all lines have the same length.

what's the fastest way to count the number of lines in c++?

user3571278
  • 701
  • 4
  • 15
  • 11
    Divide the length of the file by one more than the length of a single line. – Blender Jun 14 '15 at 05:28
  • How to get the size is a common question http://stackoverflow.com/questions/2409504/using-c-filestreams-fstream-how-can-you-determine-the-size-of-a-file – Michel Billaud Jun 14 '15 at 05:29
  • @Blender And by two more on windows? – user3125367 Jun 14 '15 at 05:34
  • @michel bollard - my boyfriend does ask that a lot :-) – Ed Heal Jun 14 '15 at 05:48
  • @user3125367: text files can have bare-`CR`, bare-`LF` or `CRLF` line breaks. Many/most Windows apps recognize bare-`LF` and `CRLF`, at least. I imagine many apps on other platforms do as well. It is not uncommon to move text files between platforms. So you should open the file and analyze the first couple of lines to discover the actual line length and line break being used, then adjust the file size calculation accordingly. – Remy Lebeau Jun 14 '15 at 16:42

0 Answers0