title: Efficient way of reading a file into an std::vector<char>?
body: <p>I'd like to avoid unnecessary copies. I'm aiming for something along the lines of:</p>
  
  <pre><code>std::ifstream testFile( "testfile", "rb" );
  std::vector&lt;char&gt; fileContents;
  int fileSize = getFileSize( testFile );
  fileContents.reserve( fileSize );
  testFile.read( &amp;fileContents[0], fileSize );
  </code></pre>
  
  <p>(which doesn't work because <code>reserve</code> doesn't actually insert anything into the vector, so I can't access <code>[0]</code>).</p>
  
  <p>Of course, <code>std::vector&lt;char&gt; fileContents(fileSize)</code> works, but there is an overhead of initializing all elements (<code>fileSize</code> can be rather big). Same for <code>resize()</code>.</p>
  
  <p>This question is not so much about how important that overhead would be. Rather, I'm just curious to know if there's another way.</p>