string::c_str() and string::data() not working for conversion to const char*
<p>I have a map structure in a class that is defined as <code>std::map&lt;const char*, double&gt;</code>, and in the constructor, I add three elements all set to zero, with they keys "MR_WP", "MR_WM", and "MR_WC". I also have several access functions to the map, but before the access is performed, there is a function that checks to make sure the key actually exists in the map. </p>

<p>Basically, I have something that says:</p>

<pre><code>if ( map.find(_key) == map.end() ) throw "error"
</code></pre>

<p>When I pass a const char* string into the access function such as getValue("MR_WP"), there is no error. </p>

<p>However, if I do it like this:</p>

<pre><code>std::string str = "MR_WP";

double value = map.getValue( str.c_str() );

-or-

std::string str = "MR_WP";

double value = map.getValue( str.data() );
</code></pre>

<p>then the error is thrown. I tried both functions, because I thought that the error might have resulted from the null character. The reason I need to do it this way, is because I want to get the last letter of the key at runtime such as:</p>

<pre><code>std::string type = getType();

std::string str = "MR_W" + type;

double value = map.getValue( str.c_str() ); //or with str.data()
</code></pre>
