Here is another question about returning const char * from function.
But I have tried it out with the following codes, it looks like everything works fine.
#include <iostream>
#include <string>
using namespace std;
const char * tocstring(){
    string str = "abcd";
    return str.c_str();
}
int main(){
    const char * p = tocstring();
    cout << p << endl;
    return 0;
}
it will output abcd as what I want. Any idea about this?
 
     
     
     
    