title: Stop carriage return from appearing in stringstream
body: <p>I'm have some text parsing that I'd like to behave identically whether read from a file or from a stringstream. As such, I'm trying to use an <code>std::istream</code> to perform all the work. In the string version, I'm trying to get it to read from a static memory byte array I've created (which was originally from a text file). Let's say the original file looked like this:</p>
  
  <pre><code>4
  </code></pre>
  
  <p>The corresponding byte array is this:</p>
  
  <pre><code>const char byte_array[] = { 52, 13, 10 };
  </code></pre>
  
  <p>Where 52 is ASCII for the character 4, then the carriage return, then the linefeed.</p>
  
  <p>When I read directly from the file, the parsing works fine.</p>
  
  <p>When I try to read it in "string mode" like this:</p>
  
  <pre><code>std::istringstream iss(byte_array);
  std::istream&amp; is = iss;
  </code></pre>
  
  <p>I end up getting the carriage returns stuck on the end of the strings I retrieve from the stringstream with this method:</p>
  
  <pre><code>std::string line;
  std::getline(is, line);
  </code></pre>
  
  <p>This screws up my parsing because the <code>string.empty()</code> method no longer gets triggered on "blank" lines -- every line contains at least a <code>13</code> for the carriage return even if it's empty in the original file that generated the binary data.</p>
  
  <p>Why is the <code>ifstream</code> behaving differently from the <code>istringstream</code> in this respect? How can I have the <code>istringstream</code> version discard the carriage return just like the <code>ifstream</code> version does?</p>