title: c++ Closing cout properly
body: <p>I wanted to write a daemon which acts as a remote shell. As such I have to close stdin, stdout and stderr.</p>
  
  <p>Now I would like to know how this is properly done.</p>
  
  <pre><code>std::streambuf * old = std::cout.rdbuf(mStdOut.rdbuf());
  std::cout &lt;&lt; "Bla" &lt;&lt; std::endl;
  std::string text = mStdOut.str();
  </code></pre>
  
  <p>This works and the stream is now redirected. But what is the meaning of 'old'? Isn't this the old buffer and should be deleted? When I try to delete it I get a null pointer exception, even though the pointer itself is not NULL. So how can iget rid of it, or can I simply ignore it? if to ignore it, is the daemon disassociated from the terminal properly?</p>
  
  <p>The same goes for stderr and stdin, but I assume the treatement would be the same.</p>