about wxString and char[100]

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
wu_yuan_chun
Knows some wx things
Knows some wx things
Posts: 38
Joined: Tue Nov 07, 2006 1:19 pm

about wxString and char[100]

Post by wu_yuan_chun » Mon Dec 18, 2006 2:52 am

is there a bug ?:



char *p = new char[100];

wxString msg = p;


------------>is there a ambigous error?


if the code like this:

char *p = new char[100];

wxString msg = wxT( p );

------------>gcc error: the Lp is not declared

S.Volkenandt
Knows some wx things
Knows some wx things
Posts: 26
Joined: Tue Nov 14, 2006 1:51 pm
Location: Duesseldorf, Germany

Post by S.Volkenandt » Mon Dec 18, 2006 8:21 am

Probably your wxWidgets is compiled in Unicode mode. Then, wxString doesn't manage character arrays, but wide character arrays. You cannot pass narrow character arrays directly. Furthermore, the wxT macro is useful only for string literals. Two ways to make this work:

Code: Select all

// using wide characters directly
wchar_t* p = new wchar_t[100]; // or use wxChar instead, to stay compatible to ANSI-Mode
wxString msg = p;

// converting narrow to wide characters
char* p = new char[100];
wxString msg( p, wxConvLibc ); // or any other wxConvXYZ, depending on the encoding of p

Post Reply