int main () {
char dest[BIG_ENOUGH];
memset(dest, '\0', sizeof(dest));
strcpy(dest, func1().c_str());
return(0);
}
std::string func1 () {
std::string s("test");
return s;
}
one of my workmates told me that the string on which c_str()
is invoked may already be destroyed before strcpy
being executed.
is this true when:
- compiled with msvc 2008(c++98) ,
- or compiled with gcc(c++11),
- or compiled with clang(c++11)?