title: C++: Redirecting STDOUT
body: <p>In my application, I want to redirect the output that would normally go to the stdout stream to a function I define. I read that you <em>can</em> redirect stdio to a file, so why not to a function?</p>
  
  <p>For example:</p>
  
  <pre><code>void MyHandler( const char* data );
  
  //&lt;&lt;Magical redirection code&gt;&gt;
  
  printf( "test" );
  std::cout &lt;&lt; "test" &lt;&lt; std::endl;
  
  //MyHandler should have been called with "test" twice, at this point
  </code></pre>
  
  <ul>
  <li>How can I achieve this / similar behaviour?</li>
  </ul>