title: Text still exists after the position of ifstream::gcount()
body: <p>I wrote a text file, then read the file to a string buffer larger than the text file.</p>
  <p>I thought there would be no text after the position of <code>ifstream::gcount()</code> because the buffer was initialized with <code>\0</code>s.</p>
  <p>But there <em>was</em> text. How is this possible?</p>
  <p>example code:</p>
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  #include &lt;fstream&gt;
  
  int main() {
      std::string path = &quot;test.txt&quot;;
  
      // write to file
      std::ofstream out(path);    
      for (int i = 1; i &lt;= 10'000; ++i) {
          std::string lineNum = std::to_string(i);
          out &lt;&lt; lineNum + &quot;xxxxxxxxxxxxxxx&quot; + lineNum + &quot;\n&quot;; 
      } 
      out.close();
  
      // read from file
      std::ifstream in(path); 
      std::string buffer;
      int bufferSize = 1'000'000; 
      buffer.resize(bufferSize); 
      in.read(buffer.data(), buffer.size()); 
  
      auto gc = in.gcount(); 
      auto found = buffer.find('\n', gc); 
      std::string substr = buffer.substr(gc - 10, 100); 
  
      std::cout &lt;&lt; &quot;gcount: &quot; &lt;&lt; gc &lt;&lt; '\n'; 
      std::cout &lt;&lt; &quot;found: &quot; &lt;&lt; found &lt;&lt; '\n'; 
      std::cout &lt;&lt; &quot;npos?: &quot; &lt;&lt; std::boolalpha &lt;&lt; (found == std::string::npos) &lt;&lt; '\n'; 
      std::cout &lt;&lt; &quot;substr:\n&quot; &lt;&lt; substr &lt;&lt; std::endl;    
  }
  </code></pre>
  <p>result:</p>
  <pre><code>gcount: 237788
  found: 237810
  npos?: false    // I thought `found` should be the same as `string::npos`.
  substr:         
  xxxx10000
  01xxxxxxxxxxxxxxx9601     // I thought there should be no text after `gcount()`.
  9602xxxxxxxxxxxxxxx9602
  9603xxxxxxxxxxxxxxx9603
  9604xxxxxxxxxxxxx
  </code></pre>
  <hr />
  <p>Executed with MSVC for 32bit, on Windows(x64).</p>
  <p>P.S. Also tried building for 64bit, but the same result.<br />
  (used <code>in.read(const_cast&lt;char*&gt;(buffer.data()), buffer.size());</code> instead of <code>in.read(buffer.data(), buffer.size());</code>)</p>