I apologize because I know similar questions, but I'm still not entirely clear. Is the following safe?
void copyStr(const char* s)
{
strcpy(otherVar, s);
}
std::string getStr()
{
return "foo";
}
main()
{
copyStr(getStr().c_str());
}
Temporary std :: string will keep returning from getStr (), but will it live long enough so that I can copy its C-string to another location? Or should I explicitly store a variable for it, e.g.
std::string temp = getStr();
copyStr(temp.c_str());
source
share