But I ran an example, no problem?
Actually there is nothing wrong with the expression:
const char* cstr2 = ss.str().c_str();
The temporary object (copy) returned ss.str()will live long enough so you can get the base c-string with c_str().
Of course, by the end of the expression, you will have a pointer const charto the object, which is probably freed (this is highly implementation dependent std::basic_string).
, , . :
auto x = ss.str();
const char* cstr2 = x.c_str();
- , str() / , x.c_str() .