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

shopping cart - Page redirect not working PHP -

php - How to modify a menu to show sub-menus -

python - Installing PyDev in eclipse is failed -