title: C++ ifstream will read some values then stop
body: <p>I am trying to write a program that reads 940 4-byte long values of binary data [hex] from a bin file, and output the values to console. I have ifstream::read, cout and seekg operations in a loop. </p>
  
  <p>It will work for the first 10 or so iterations, and then in one iteration skip the read and write operations, preform the seekg operation, and continue on reading and writing. Also the last 200 lines or so are coming out the same value.</p>
  
  <p>It will work properly for 12 iterations, then it will start outputting the wrong numbers. At this point it goes from address 0x230 to 0x28B when it should be at 0x260. It looks like read and cout are not called in this particular iteration.</p>
  
  <p>The last correct value reads 3f4fc938. The next value should be 3ef646c1.</p>
  
  <p>Does anyone know why this would fail? Any help is appreciated.</p>
  
  <p>This is the program:</p>
  
  <pre><code>int main(int argc, char* argv[]) {
      fstream in;
      uint32_t buffer;
      in.open(argv[1]);
      in.seekg(0x6500,in.beg);
      for(int i = 0; i &lt; 940; i++) {
          in.read(reinterpret_cast&lt;char*&gt; (&amp;buffer),4);
          cout &lt;&lt; hex &lt;&lt; buffer &lt;&lt; endl;
          in.seekg(0x2c,in.cur);
      }
  }
  </code></pre>