title: stringstream write skipping whitespace
body: <p>I was under the impression that the unformatted <code>write()</code> would copy bytes verbatim to the <code>ostream</code> on which it is called. I was also told by another SO user that 'Write function doesn't skip anything. If you have a problem using <code>stringstream</code>, ask a question.'</p>
  
  <p>However, in some recent code using <code>stringstream</code> I found this not to be the case.</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;fstream&gt;
  #include &lt;sstream&gt;
  #include &lt;algorithm&gt;
  #include &lt;iterator&gt;
  
  int main()
  {
      {
          const std::string msg = "This is a secret message!";
          std::stringstream ss;
          const int size = msg.size();
          // ss &lt;&lt; std::noskipws;
          ss.write( reinterpret_cast&lt;const char*&gt;(&amp;size),sizeof( size ) );
          ss.write( msg.data(),msg.size() );
  
          std::ofstream out( "secret.txt",std::ios::binary );
          std::transform( std::istream_iterator&lt;char&gt;( ss ),std::istream_iterator&lt;char&gt;(),
                          std::ostream_iterator&lt;char&gt;( out ),[]( const char c ) { return c + 113; } );
      }
  
      {
          std::stringstream ss;
          std::ifstream in( "secret.txt",std::ios::binary );
          std::transform( std::istream_iterator&lt;char&gt;( in ),std::istream_iterator&lt;char&gt;(),
                          std::ostream_iterator&lt;char&gt;( ss ),[]( const char c ) { return c - 113; } );
          int size;
          ss.read( reinterpret_cast&lt;char*&gt;(&amp;size),sizeof( size ) );
          std::string msg( size,'@' );
          ss.read( &amp;msg[0],size );
          std::cout &lt;&lt; "Decoded message is: " &lt;&lt; msg &lt;&lt; std::endl;
      }
  
      return 0;
  }
  </code></pre>
  
  <p>The output for this code is as follows:</p>
  
  <blockquote>
    <p>Decoded message is: Thisisasecretmessage!@@@@</p>
  </blockquote>
  
  <p>However, if I uncomment the <code>ss &lt;&lt; std::noskipws;</code> line then the output is as expected, with whitespace characters preserved.</p>
  
  <p>What am I missing here?</p>