title: Fastest way to find the number of lines in a text (C++)
body: <p>I need to read the number of lines in a file before doing some operations on that file. When I try to read the file and increment the <code>line_count</code> variable at each iteration until I reach <code>EOF</code>. It was not that fast in my case. I used both <code>ifstream</code> and <code>fgets</code>. They were both slow. Is there a hacky way to do this, which is also used by, for instance BSD, Linux kernel or berkeley db (may be by using bitwise operations).</p>
  <p>The number of lines is in the millions in that file and it keeps getting larger, each line is about 40 or 50 characters. I'm using Linux.</p>
  <p><strong>Note:</strong><br />
  I'm sure there will be people who might say use a DB idiot. But briefly in my case I can't use a db.</p>