title: c++ stringstream to ostream to string
body: <p>I would like to be able to do:</p>
  
  <pre><code>foo(stringstream()&lt;&lt;"number = " &lt;&lt; 500);
  </code></pre>
  
  <p>EDIT: single line solution is crucial since this is for logging purposes. These will be all around the code.</p>
  
  <p>inside foo will print the string to screen or something of the sort.</p>
  
  <p>now since stringstream's operator&lt;&lt; returns ostream&amp;, foo's signature must be:</p>
  
  <pre><code>foo(ostream&amp; o);
  </code></pre>
  
  <p>but how can I convert ostream&amp; to string? (or char*).
  Different approaches to achieving this use case are welcome as well.</p>