Copying an ostream to a std::string
<p>I've a program that used to run as a commandline, hence has lots of <code>couts</code> in it. I was wondering if there was a way of creating an <code>ostream</code> object in the class that calls this program and initialize that programs constructor with something like</p>

<pre><code>Import(ostream &amp; text_out= std::cout):out(text_out)
</code></pre>

<p>and replace all my calls to <code>cout</code> with out, thereby switching where the output goes.</p>

<p>At the end of each function call, I could then extract the <code>ostream</code> object to a string, and send it to my MFC object.</p>

<p>This would mean my base code would be good if called either as a commandline or an MFC program, if I could get it to work. This could be me thinking along the wrong track, but I'm curious to see if this is possible.</p>
