title: Reading formatted lines from stringstream performantly
body: <p>For loading large amounts of vertices from a text file, I'm loading the whole file into memory and then I'd like to scan each line for the three floats.
  The following works, but I'd like to know whether it's good or wasteful.</p>
  
  <pre><code>std::stringstream sstr;
  sstr &lt;&lt; file.rdbuf();    // file is an ifstream
  
  for (uint i=0; i&lt;num_verts; ++i)
  {
      sstr.getline(line, bufsz);
      std::istringstream iss(line);
      iss &gt;&gt; verts[i].x &gt;&gt; verts[i].y &gt;&gt; verts[i].z;
  }
  </code></pre>
  
  <p>On the reference site cplusplus.com I found the following for <code>istringstream</code>:</p>
  
  <blockquote>
    <p>(2) initialization constructor: Constructs an istringstream object with a copy of str as content.</p>
  </blockquote>
  
  <p>So if <code>istringstream</code> is really copying each string upon construction, then that's very wasteful, especially since I already have a stringstream in the first place.</p>
  
  <p>Compared with <code>sscanf</code>, the above is indeed quite slow: 1.94 seconds vs. 0.56s for <code>sscanf</code>.</p>
  
  <p>Is the string being copied upon initialization of <code>iss</code>?</p>
  
  <p>How would one read formatted values while simultaneously advancing in the string line-wise with just the stringstream?</p>
  
  <p>Or less specific: What's the C++ method for the above case that's equally well performing as <code>sscanf</code>?</p>