title: Trouble with std::ostringstream as function parameter
body: <p>So I got stuck on a simple print-function today and I really don't know how to fix this problem. Basically I want to pass my Strings to a function in a std::cout-style like this:</p>
  
  <pre><code>foo(std::ostringstream() &lt;&lt; "Hello" &lt;&lt; " World!");
  </code></pre>
  
  <p>And from what I've read it should be possible by a function along the lines of</p>
  
  <pre><code>void foo(std::ostringstream&amp; in)
  </code></pre>
  
  <p>but when implementing I get a somewhat strange behavior:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;sstream&gt;
  
  void foo(std::ostringstream&amp; in)
  {
      std::cout &lt;&lt; in.str();
  }
  
  int main()
  {
      std::ostringstream working;
      working &lt;&lt; "Hello" &lt;&lt; " World!";
      foo(working);                   // OK
      std::ostringstream notWorking;
      notWorking &lt;&lt; "Hello";
      foo(notWorking&lt;&lt;" World!");     // Not OK?!
      return 0;
  }
  </code></pre>
  
  <p>While the first call of foo seems fine and works like expected, the second one refuses to compile even though they should (from my perspective) be technically the same thing.</p>
  
  <p>Error:</p>
  
  <pre><code>error C2664: 'void foo(std::ostringstream &amp;)': cannot convert parameter 1 from 'std::basic_ostream&lt;char,std::char_traits&lt;char&gt;&gt;' to 'std::ostringstream &amp;'
  </code></pre>
  
  <p>I'm using MS Visual Studio 2013 Express on Win7 x64</p>