R
richardclay09
In this snippet:
void f(const char* c) {...use c in a read-only way...}
std:
stringstream oss;
oss << "blah blah";
f(oss.str().c_str());
oss.str() returns a *copy* of the buffer as a std::string. In this case
this copy is anonymous, and the return value of its c_str() method is
passed to f(). Is the anonymous std::string instance guaranteed (by the
standards) to last long enough for f() to safely use its c_str() value?
void f(const char* c) {...use c in a read-only way...}
std:
oss << "blah blah";
f(oss.str().c_str());
oss.str() returns a *copy* of the buffer as a std::string. In this case
this copy is anonymous, and the return value of its c_str() method is
passed to f(). Is the anonymous std::string instance guaranteed (by the
standards) to last long enough for f() to safely use its c_str() value?