title: getting cout output to a std::string
body: <p>I have the following <code>cout</code> statement. I use char arrays because I have to pass to <code>vsnprintf</code> to convert variable argument list and store in <code>Msg</code>.</p>
  
  <p>Is there any way we can get <code>cout</code> output to C++ <code>std::string</code>?</p>
  
  <pre><code>char Msg[100];
  char appname1[100];
  char appname2[100];
  char appname3[100]; 
  
  // I have some logic in function which some string is assigned to Msg.
  std::cout &lt;&lt; Msg &lt;&lt; " "&lt;&lt; appname1 &lt;&lt;":"&lt;&lt; appname2 &lt;&lt; ":" &lt;&lt; appname3 &lt;&lt; " " &lt;&lt; "!" &lt;&lt; getpid() &lt;&lt;" " &lt;&lt; "~" &lt;&lt; pthread_self() &lt;&lt; endl;
  </code></pre>