Std::string get assigned by a function returning a char *
<h2>Update: for the getValue function I have no control, so is there anything I can do from my side?</h2>

<p>I have a kind of dumb question about string and char * basic. </p>

<p>I'm using a function that returns a char * value,</p>

<pre><code>const char *getValue(const char *key)
{
    //if key found, and valueString is a string
      return valueString.c_str();
    //else
      return NULL;
}
</code></pre>

<p>then I initialized a string to hold the return value,</p>

<pre><code>std::string value = getValue(key);
</code></pre>

<p>problem is, whenever the value is not found, which means the function returns NULL, my assignment line will run into an exception. But when there is a legal return value, everything is working fine. </p>

<p>I'm wondering
1. Is this usage totally wrong? means I should never mix char * with string?
2. If not, then when there is a legal pointer returned, does my string automatically make a copy and store it?
3. What is the best way to do this?</p>

<p>Thanks.</p>
