Capturing and formatting cout
<p>How can I capture the input of cout?</p>

<p>Example:</p>

<p>if I enter:</p>

<pre><code>std::cout&lt;&lt;"Some normal text here" &lt;&lt; fout &lt;&lt;"Test %, %", 1, 2&lt;&lt; "works 100% fine."&lt;&lt;std::endl
</code></pre>

<p>then it would print:</p>

<blockquote>
  <p>"Some normal text here Test 1, 2 works 100% fine."</p>
</blockquote>

<p>The 100% isn't formatted because of the &lt;&lt; operator. Only things directly after the fout would be formatted until it met the &lt;&lt; operator.</p>

<p>Can I do that?</p>

<pre><code>#include &lt;iostream&gt;
#include &lt;sstream&gt;
#include &lt;vector&gt;
#include &lt;algorithm&gt;


std::ostream&amp; fout (std::ostream&amp; I)
{
    //Some how format my text here.. Then return it as the ostream.
    return I;
}

int main(int argc, char* argv[])
{    
    std::cout&lt;&lt; fout &lt;&lt; "Test %", 1 &lt;&lt; "Other stuff 20%.";
    //So Anything after fout&lt;&lt; should be stolen and formatted then given back to cout.. Other stuff 20% isn't formatted because of the &lt;&lt;.
}
</code></pre>

<p>I know it seems silly but I really want to know how it's done. I saw that boost does something similar by doing Format("%20") % SomeVar</p>

<p>But I want to figure out how to do it with the insertion operator and using the comma operator. Any ideas or anything similar?</p>
