title: string.c_str() outputs gibberish - but only sometimes
body: <p>I'm writing a short OpenGL-program, and need to import the shader source, which I use the following code for (OpenGL wants the shader source as a c-string):</p>
  
  <pre><code>    std::ifstream t("GLshader.vert");
      if (!t.is_open()) {
          std::cerr &lt;&lt; "vertex shader open failed" &lt;&lt; std::endl;
      }
      std::stringstream buffer;
      buffer &lt;&lt; t.rdbuf();
  
  
      const char* source = buffer.str().c_str();
      std::string s = buffer.str().c_str();
      std::cerr &lt;&lt; "vs string :" &lt;&lt; std::endl &lt;&lt; s &lt;&lt; std::endl;
      std::cerr &lt;&lt; "vs source:" &lt;&lt; std::endl &lt;&lt; source &lt;&lt; std::endl;
  </code></pre>
  
  <p>What has me really stumped is the fact that <em>sometimes</em> everything is fine, and the last two lines of code output the same text. <em>Sometimes</em> however, for some reason, the output is instead this: </p>
  
  <pre><code>vs string:
  /* actual shader code*/
  #version 330 core
  
  layout(location=0) in vec3 position;
  
  out vec3 pos;
  out vec2 texcoord;
  
  void main(){
    pos = position;
    texcoord = (position.xy +1.f) / 2.f;
    gl_Position = vec4(position, 1.0f);
  }
  
  vs source:
  @ð4
  </code></pre>
  
  <p>The printouts, as well as the string, is there because I kept getting shader compilation errors (again, <em>sometimes</em>), and thought it might be some weird concurrency issue with reading the file. Obviously that works fine, but for some reason the c-string creation sometimes fails. </p>
  
  <p>The function is called in a .dll, and I'm using visual studio. (I've run the .exe outside of VS, and the problem occurs there as well)</p>
  
  <p>I'm really out of ideas here, anyone have an answer?</p>