I am newbie in c++. In the following code, I call two methods, first initialize and then connect:
const char* str;
void initialize() {
string temp = "blah blah";
str= temp.c_str();
cout << "str: " << str << endl; //prints: "str: blah blah"
temp = "foo bar";
cout << "str: " << str << endl; //prints: "str: foo bar"
}
I want to know why changing temp variable, causes str variable to change too and what is the best and safe way to set a value for const char*?
Thanks