wxString convert to char*, so weird! Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
hou
Knows some wx things
Knows some wx things
Posts: 34
Joined: Wed Apr 16, 2008 3:14 am

wxString convert to char*, so weird!

Post by hou »

I want to change a wxString to char*, then I can use:

wxString strTemp;
const char* pz = strTemp.c_str();
const char* pz = strTemp.char_str();
const char* pz = strTemp.mb_str();
const char* pz = strTemp.ToAsicc();
...

but I find aboving methods all return a "\0\0....somechar..."
under CodeBlocks(my OS is ubuntu), only this way:

char temp[40];
strcpy(temp,strTemp.mb_str());
const char* a_pszFile = temp;

can return the right char*.

Does anyone have some better method? And more important is please explain the difference between these methods, tks.
My brother is going to go to university.
framepointer
Super wx Problem Solver
Super wx Problem Solver
Posts: 264
Joined: Mon Aug 07, 2006 3:25 pm
Location: Baia Mare, Romania
Contact:

Post by framepointer »

You could try

Code: Select all

wxString sStr("test");
const char * pSz = (const char *) sStr;

wxString * pStr = new wxString("test");
const char * pSz1 = (const char *) *pStr;
It's the best way to convert to "const char *" since the operator is overloaded.

Regards
Software is like sex,
It's better when it's free.
~Linus Torvalds
User avatar
doublemax
Moderator
Moderator
Posts: 19114
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Post by doublemax »

Use the source, Luke!
Post Reply