title: string and const char* and .c_str()?
body: <p>I'm getting a weird problem and I want to know why it behaves like that. I have a class in which there is a member function that returns <code>std::string</code>. My goal to convert this <code>string</code> to <code>const char*</code>, so I did the following </p>
  
  <pre><code>    const char* c;
      c = robot.pose_Str().c_str();  // is this safe??????
      udp_slave.sendData(c);
  </code></pre>
  
  <p>The problem is I'm getting a weird character in Master side. However, if I do the following </p>
  
  <pre><code>    const char* c;
      std::string data(robot.pose_Str());
      c = data.c_str();
      udp_slave.sendData(c);
  </code></pre>
  
  <p>I'm getting what I'm expecting. My question is what is the difference between the two aforementioned methods?</p>