title: Redirecting stderr to stdout using string stream
body: <p>I have a code like this</p>
  
  <pre><code>int main()
  {
      std::stringstream oss;
      std::cerr.rdbuf( oss.rdbuf() );
  
      std::cerr &lt;&lt; "this goes to cerr";
      std::cout &lt;&lt; "[" &lt;&lt; oss.str() &lt;&lt; "]";
  }
  </code></pre>
  
  <p>But i get the output of the program as </p>
  
  <pre><code>[this goes to cerr]Segmentation fault
  </code></pre>
  
  <p>How does the program segfault?</p>