Page 1 of 1

about wxString and char[100]

Posted: Mon Dec 18, 2006 2:52 am
by wu_yuan_chun
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

Posted: Mon Dec 18, 2006 8:21 am
by S.Volkenandt
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