title: How to read entire stream into a std::string?
body: <p>I'm trying to read an entire stream (multiple lines) into a string. </p>
  
  <p>I'm using this code, and it works, but it's offending my sense of style... Surely there's an easier way? Maybe using stringstreams?</p>
  
  <pre><code>void Obj::loadFromStream(std::istream &amp; stream)
  { 
    std::string s;
  
    std::streampos p = stream.tellg();  // remember where we are
  
    stream.seekg(0, std::ios_base::end); // go to the end
    std::streamoff sz = stream.tellg() - p;  // work out the size
    stream.seekg(p);        // restore the position
  
    s.resize(sz);          // resize the string
    stream.read(&amp;s[0], sz);  // and finally, read in the data.
  </code></pre>
  
  <p><hr>
  Actually, a <code>const</code> reference to a string would do as well, and that may make things easier...</p>
  
  <pre><code>const std::string &amp;s(... a miracle occurs here...)
  </code></pre>