title: std::fstream::tellg() outputs file cursor pointer incorrectly?
body: <p>I have a <code>std::fstream</code>, which I imported using</p>
  
  <pre><code>std::fstream myFile { "C:/path/to/file.txt" };
  </code></pre>
  
  <p>When I want to read the first byte, I use</p>
  
  <pre><code>char c;
  cout &lt;&lt; myFile.tellg() &lt;&lt; endl; // Correctly outputs 0 (begining of file)
  myFile.read(&amp;c, 1);
  cout &lt;&lt; myFile.tellg() &lt;&lt; endl; // Should output 1, but it outputs
                                  // FFFFFFFFFFFFFFFA
  myFile.read(&amp;c, 1);
  cout &lt;&lt; myFile.tellg() &lt;&lt; endl; // Should output 2, but it outputs
                                  // FFFFFFFFFFFFFFFB
  </code></pre>
  
  <p>What's happening here?</p>
  
  <p>I tried putting</p>
  
  <pre><code>midi_file.seekg(0, ios_base::beg);
  </code></pre>
  
  <p>or</p>
  
  <pre><code>midi_file.seekg(0, myFile.beg);
  </code></pre>
  
  <p>But the cursor moves to <code>FFFFFFFFFFFFFFFA</code> whenever I try to read a byte.</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>I don't know if it has something to do, but I did an endianness test and these are the results:</p>
  
  <pre><code>bool endianness = *reinterpret_cast&lt;short*&gt;("10") &amp; 1; // Outputs 1
  </code></pre>
  
  <p><strong>EDIT 2:</strong></p>
  
  <p>The file is broken, as the output is not the same with another file, but why is it?</p>
  
  <p>Here is the byte data from the file, taken from HxD, which is a <code>.midi</code> file:</p>
  
  <pre><code>4D 54 68 64 00 00 00 06 00 01 00 03 00 04 4D 54
  72 6B 00 00 00 A1 00 C0 69 00 90 3C 5A 01 41 5A
  01 45 5A 01 48 5A 01 49 5A 01 48 5A 01 45 5A 01
  41 5A 01 3C 5A 01 37 5A 01 33 5A 01 30 5A 01 30 
  5A 01 30 5A 01 33 5A 01 37 5A 01 3C 5A 01 41 5A 
  01 45 5A 01 48 5A 01 49 5A 01 48 5A 01 45 5A 01 
  41 5A 01 3C 5A 01 37 5A 01 33 5A 01 30 5A 01 30 
  5A 01 30 5A 01 33 5A 01 37 5A 01 3C 5A 01 41 5A 
  01 45 5A 01 48 5A 01 49 5A 01 48 5A 01 45 5A 01 
  41 5A 01 3C 5A 01 37 5A 01 33 5A 01 30 5A 01 30 
  5A 01 30 5A 01 33 5A 01 37 5A 01 3C 5A 01 41 5A 
  01 45 00 00 FF 2F 00 4D 54 72 6B 00 00 00 41 00 
  C1 72 05 91 3C 5A 00 40 5A 00 43 5A 00 48 5A 0A 
  35 5A 00 41 5A 00 44 5A 00 49 5A 0A 37 5A 00 40 
  5A 00 43 5A 00 48 5A 0A 41 5A 00 47 5A 0A 30 5A 
  00 40 5A 00 43 5A 00 48 5A 05 32 00 00 FF 2F 00 
  4D 54 72 6B 00 00 00 26 00 C2 47 0A 92 50 64 01 
  52 64 09 50 78 00 52 78 0A 50 00 01 52 00 09 50 
  78 01 50 00 0A 52 00 00 50 00 00 FF 2F 00
  </code></pre>
  
  <p><strong>EDIT 3:</strong></p>
  
  <p>Here is the full code of this test:</p>
  
  <pre><code>#include &lt;fstream&gt;
  #include &lt;iostream&gt;
  
  int main() {
      cout &lt;&lt; std::hex &lt;&lt; std::setfill('0') &lt;&lt; std::uppercase;
  
      fstream midi_file{ "D:/Descargas/OutFile.midi" };
  
      cout &lt;&lt; midi_file.good() &lt;&lt; endl; // Outputs 1
  
      char c;
      cout &lt;&lt; midi_file.tellg() &lt;&lt; endl; // Correctly outputs 0 (begining of file)
      midi_file.read(&amp;c, 1);
      cout &lt;&lt; midi_file.tellg() &lt;&lt; endl; // Erroneously outputs FFFFFFFFFFFFFFFA
      midi_file.read(&amp;c, 1);
      cout &lt;&lt; midi_file.tellg() &lt;&lt; endl; // Erroneously outputs FFFFFFFFFFFFFFFB
  
      // Endianness test:
      cout &lt;&lt; (*reinterpret_cast&lt;short*&gt;("10") &amp; 1) &lt;&lt; endl; // Outputs 1
  
      return 0;
  }
  </code></pre>