title: Why does calling c_str() on a function that returns a string not work?
body: <p>I have a function that is returning a string. However, when I call it and do <code>c_str()</code> on it to convert it into a <code>const char*</code>, it only works when I store it into another string first. If I directly call <code>c_str()</code> off of the function, it stores garbage value in the <code>const char*</code>.</p>
  <p>Why is this happening? Feel like I'm missing something very fundamental here...</p>
  <pre><code>string str = SomeFunction();
  const char* strConverted = str.c_str(); // strConverted stores the value of the string properly
  const char* charArray= SomeFunction().c_str(); // charArray stores garbage value
  
  static string SomeFunction()
  {
      string str;
      // does some string stuff
      return str;
  }
  </code></pre>