title: ifstream.eof() - end of file is reached before the real end
body: <p>I have a roughly 11.1G binary file where stores a series of the depth frames from the Kinect. There are 19437 frames in this file. To read one frame per time, I use <strong><em>ifstream</em></strong> in <strong><em>fstream</em></strong> but it reaches <strong><em>eof</em></strong> before the real end of the file. (I only got the first 20 frames, and the function stops because of the <strong><em>eof</em></strong> flag)</p>
  
  <p>However, all frames can be read by using <strong><em>fread</em></strong> in <strong><em>stdio</em></strong> instead.</p>
  
  <p>Can anyone explain this situation? Thank you for precious time on my question.</p>
  
  <p>Here are my two functions:</p>
  
  <pre><code>// ifstream.read() - Does Not Work: the loop will stop after 20th frame because of the eof flag
  ifstream depthStream("fileName.dat");
  if(depthStream.is_open())
  {
    while(!depthStream.eof())
    {
      char* buffer = new char[640*480*2];
      depthStream.read(buffer, 640*480*2);
  
      // Store the buffer data in OpenCV Mat
  
      delete[] buffer;
    }
  }
  
  // fread() - Work: Get 19437 frames successfully
  FILE* depthStream
  depthStream = fopen("fileName.dat", "rb");
  if(depthStream != NULL)
  {
    while(!feof(depthStream))
    {
      char* buffer = new char[640*480*2];
      fread(buffer, 1, 640*480*2, depthStream);
  
      // Store the buffer data in OpenCV Mat
  
      delete[] buffer;
  }
  </code></pre>
  
  <p>Again, thank you for precious time on my question</p>