title: Performance of creating a C++ std::string from an input iterator
body: <p>I'm doing something really simple: slurping an entire text file from disk into a <code>std::string</code>. My current code basically does this:</p>
  
  <pre><code>std::ifstream f(filename);
  return std::string(std::istreambuf_iterator&lt;char&gt;(f), std::istreambuf_iterator&lt;char&gt;());
  </code></pre>
  
  <p>It's very unlikely that this will ever have any kind of performance impact on the program, but I still got curious whether this is a slow way of doing it.</p>
  
  <p>Is there a risk that the construction of the string will involve a lot of reallocations? Would it be better (that is, faster) to use <code>seekg()</code>/<code>tellg()</code> to calculate the size of the file and <code>reserve()</code> that much space in the string before doing the reading?</p>