title: Passing std::string reference from std::stringstream as parameter
body: <p>I am using std::stringstream to construct a string and then attempting to pass the completed string as a reference to a function which takes as a parameter a std::string&amp;.</p>
  
  <p>I am getting a compilation error on GCC:</p>
  
  <pre><code>../src/so.cpp:22:21: error: invalid initialization of non-const reference of type ‘std::string&amp; {aka std::basic_string&lt;char&gt;&amp;}’ from an rvalue of type ‘std::basic_stringstream&lt;char&gt;::__string_type {aka std::basic_string&lt;char&gt;}’
  ../src/so.cpp:12:6: error: in passing argument 1 of ‘void myFunc(std::string&amp;)’
  make: *** [src/so.o] Error 1
  </code></pre>
  
  <p>The same code is compiling on Windows VS2012, but fails on my Linux and Android builds. What is the reason for this?</p>
  
  <p>I can work around the issue by temporarily assigning ss.str() to a temporary std::string and then passing that string by reference, but this seems slightly silly. What is the correct way to do this cleanly?</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;sstream&gt;
  
  void myFunc (std::string&amp; msg)
  {
      std::cout &lt;&lt; msg &lt;&lt; std::endl;
  }
  
  int main (void)
  {
      std::stringstream ss;
      ss &lt;&lt; "this is a test";
  
      myFunc (ss.str());              // Fails
  
      std::string s = ss.str();
      myFunc (s);                     // Pass
  
      return 0;
  }
  </code></pre>