title: Why does std::ends cause string comparison to fail?
body: <p>I spent about 4 hours yesterday trying to fix this issue in my code. I simplified the problem to the example below.</p>
  <p>The idea is to store a string in a <code>stringstream</code> ending with <code>std::ends</code>, then retrieve it later and compare it to the original string.</p>
  <pre><code>#include &lt;sstream&gt;
  #include &lt;iostream&gt;
  #include &lt;string&gt;
  
  int main( int argc, char** argv )
  {
      const std::string HELLO( &quot;hello&quot; );
  
      std::stringstream testStream;
  
      testStream &lt;&lt; HELLO &lt;&lt; std::ends;
  
      std::string hi = testStream.str();
  
      if( HELLO == hi )
      {
          std::cout &lt;&lt; HELLO &lt;&lt; &quot;==&quot; &lt;&lt; hi &lt;&lt; std::endl;
      }
  
      return 0;
  }
  
  </code></pre>
  <p>As you can probably guess, the above code when executed will not print anything out.</p>
  <p>Although, if printed out, or looked at in the debugger (VS2005), <code>HELLO</code> and <code>hi</code> look identical, their <code>.length()</code> in fact differs by 1. That's what I am guessing is causing the <code>==</code> operator to fail.</p>
  <p>My question is why. I do not understand why <code>std::ends</code> is an invisible character added to string <code>hi</code>, making <code>hi</code> and <code>HELLO</code> different lengths even though they have identical content. Moreover, this invisible character does not get trimmed with boost trim. However, if you use <code>strcmp</code> to compare <code>.c_str()</code> of the two strings, the comparison works correctly.</p>
  <p>The reason I used <code>std::ends</code> in the first place is because I've had issues in the past with <code>stringstream</code> retaining garbage data at the end of the stream. <code>std::ends</code> solved that for me.</p>