title: redirect std::cout to a custom writer
body: <p>I want to use this snippet from <a href="http://www.mr-edd.co.uk/?p=16" rel="nofollow noreferrer">Mr-Edd's iostreams article</a> to print std::clog somewhere.</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;iomanip&gt;
  #include &lt;string&gt;
  #include &lt;sstream&gt;
  
  int main()
  {
      std::ostringstream oss;
  
      // Make clog use the buffer from oss
      std::streambuf *former_buff =
          std::clog.rdbuf(oss.rdbuf());
  
      std::clog &lt;&lt; "This will appear in oss!" &lt;&lt; std::flush;
  
      std::cout &lt;&lt; oss.str() &lt;&lt; '\\n';
  
      // Give clog back its previous buffer
      std::clog.rdbuf(former_buff);
  
      return 0;
  }
  </code></pre>
  
  <p>so, in a mainloop, I will do something like </p>
  
  <pre><code>while (! oss.eof())
  {
      //add to window text somewhere
  }
  </code></pre>
  
  <p>Here's the <a href="http://en.cppreference.com/w/cpp/io/basic_ostringstream" rel="nofollow noreferrer">ostringstream docs</a> but I'm having trouble understanding the best way to do this.  I have a method that displays the text, I just want to call it with any data in the ostringstream.</p>
  
  <p>What is the easiest/best way to get anything sent to std::clog redirected to a method of my choice?  is it as above, and fill in the while !eof part (not sure how), or is there a better way, say by overloading some 'commit' operator somewhere that calls my method?  I'm loking for quick and easy, I really don't want to start defining sinks and such with boost iostreams as the article does - that stuff is way over my head.</p>