title: Convert std::string to const char* for printf Consumption
body: <p>Let us consider the below code example. Basically, <code>getMessage1</code> (internally) creates an <code>std::string</code> which is meant to be returned and then printed via <code>printf</code>. How do I convert/cast/manipulate variable <code>myString</code> so that the output looks like the one from <code>getMessage2</code>? </p>
  
  <p>I am aware that <code>getMessage3</code> works, but it requires me to include <code>.c_str()</code> in every <code>printf</code> statement (and I'd like to avoid this extra <em>suffix</em>).</p>
  
  <pre><code>#include &lt;string&gt;
  
  const char* getMessage1() {
      std::string myString = "SomeOutput";
      return myString.c_str();
  }
  
  const char* getMessage2() {
      return "SomeOutput"; 
  }
  
  std::string getMessage3() {
      std::string myString = "SomeOutput";
      return myString;
  }
  
  int main() {
      printf("#1: %s \n", getMessage1());         // prints #1: ╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠¿ⁿ9"w
      printf("#2: %s \n", getMessage2());         // prints #2: SomeOutput
      printf("#3: %s \n", getMessage3().c_str()); // prints #3: SomeOutput
  
      return 0;
  }
  </code></pre>