title: CRLF end of line and ostringstream
body: <p>I am trying to use a ostringstream to build a string which uses the platform standard line endings (so for me it is CRLF since I am developing for Windows). I tried the following code:</p>
  
  <pre><code>std::ostringstream out;
  out &lt;&lt; "line1\nline2\n";
  const char* result = out.str().c_str(); // In result end of lines are '\n' instead
                                          // of the expected '\r\n'
  </code></pre>
  
  <p>Since ostringstream is opened by default in text mode, I thought it would perform the end of line conversion (like an ofstream) but the resulting char buffer does not contain the expected CRLF end of lines....</p>
  
  <h3>Edit:</h3>
  
  <p>For those who wondered why I needed the CRLF ending internally: I copy the text into the Windows clipboard and user often copy that content to Notepad and without the CRLF ending the end of lines are lost during that last operation....</p>
  
  <h3>My solution:</h3>
  
  <p>Finally I decided to use the boost library to replace \n with \r\n:</p>
  
  <pre><code>boost::replace_all( str, "\n", "\r\n" );
  </code></pre>