c++ - Converting form CString to const char* -


i've wrote method convert form cstring const char *:

const char* caesdlg::converttochar(cstring str) {     cstringa charstr(str);     const char *cstr = (const char *)charstr;     return cstr; } 

but when trying put in const char * doesn't return correct value!

const char *test = converttochar(filepath); 

the value of charstr gets destroyed @ end of function before caller assigns variable.

you don't need function, caller can use cstringa directly , note test valid before sfilepatha goes out of scope.

cstringa sfilepatha(filepath); const char *test = sfilepatha; 

Comments

Popular posts from this blog

jquery - How do you format the date used in the popover widget title of FullCalendar? -

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -