Is there another efficient way to write code below not using static string variable? The reason is that, I use the code below to illustrate the crash happening in a bigger project that uses this static string variable. But if I remove the static keyword, the code will not crash, but the contents of string variable are nothing.
std::string conversation;
const char *GetFoo()
{
static std::string word;
word ="hello ";
word +="buddy.";
word +=" How are things?";
return word.c_str();
}
void CallGetFoo()
{
const char *pp = GetFoo();
conversation +=pp;
cout<<pp;
}
int _tmain(int argc, _TCHAR* argv[])
{
CallGetFoo();
return 0;
}