how to have a temporary char array in a function as its returned value?
like
char* nFunction(string& s){
const char* c=s.c_str();
char cn[9];
cn[0]=c[0];
cn[1]=c[1];
cn[2]=c[2];
return cn;
}
int main(){
string s("foo bar");
cout<<"return= "<<nFunction(s) ;
}
not work... what's the correct?
Thanks.
like
char* nFunction(string& s){
const char* c=s.c_str();
char cn[9];
cn[0]=c[0];
cn[1]=c[1];
cn[2]=c[2];
return cn;
}
int main(){
string s("foo bar");
cout<<"return= "<<nFunction(s) ;
}
not work... what's the correct?
Thanks.
Last edited: