title: Fast textfile reading in c++
body: <p>I am currently writing a program in c++ which includes reading lots of large text files. Each has ~400.000 lines with in extreme cases 4000 or more characters per line. Just for testing, I read one of the files using ifstream and the implementation offered by cplusplus.com. It took around 60 seconds, which is way too long. Now I was wondering, is there a straightforward way to improve reading speed?</p>
  
  <p>edit:
  The code I am using is more or less this: </p>
  
  <pre><code>string tmpString;
  ifstream txtFile(path);
  if(txtFile.is_open())
  {
      while(txtFile.good())
      {
          m_numLines++;
          getline(txtFile, tmpString);
      }
      txtFile.close();
  }
  </code></pre>
  
  <p>edit 2: The file I read is only 82 MB big. I mainly said that it could reach 4000 because I thought it might be necessary to know in order to do buffering.</p>
  
  <p>edit 3: Thank you all for your answers, but it seems like there is not much room to improve given my problem. I have to use readline, since I want to count the number of lines. Instantiating the ifstream as binary didn't make reading any faster either. I will try to parallelize it as much as I can, that should work at least.</p>
  
  <p>edit 4: So apparently there are some things I can to. Big thank you to sehe for putting so much time into this, I appreciate it a lot! =) </p>