title: C++ stringstream to char* conversion memory allocation
body: <p>Can anyone explain how the following code is working and does <strong>not</strong> crash the application?</p>
  
  <pre><code>int main() {
      char *tempStr = new char[5];
      tempStr[0] = '\0';
      string stemp = "helloworld";
      stringstream sstream;
      sstream.str(stemp);
      cout &lt;&lt; "len before = " &lt;&lt; strlen(tempStr);
      sstream &gt;&gt; tempStr;
      cout &lt;&lt; "len after = " &lt;&lt; strlen(tempStr) &lt;&lt; endl;
      cout &lt;&lt; tempStr &lt;&lt; endl;
      delete[] tempStr;
      return 1;
  }
  </code></pre>
  
  <p>I am getting the output as </p>
  
  <pre><code>len before = 0
  len after = 10
  helloworld
  </code></pre>
  
  <ol>
  <li>Did <code>stringstream</code> allocate memory for the extra characters in the char pointer? </li>
  <li>Also want to know the correct way to copy data from <code>stringstream</code> to char* array, without exceeding the memory allocated for <code>char*</code>?</li>
  </ol>