Skip to content

WxString

Convert

std::string to wxString

std::string stlstring = "Hello world";
// assuming your string is encoded as UTF-8, change the wxConv* parameter as needed
wxString mystring(stlstring.c_str(), wxConvUTF8);

Starting from wxWidgets 3.0, you may also use the appropriate constructor

std::string stlstring = "Hello world";
// assuming your string is encoded as the current locale encoding (wxConvLibc)
wxString mystring(stlstring);

wxString to std::string

wxWidgets 2.8 :

wxString mystring(wxT("HelloWorld"));
std::string stlstring = std::string(mystring.mb_str());

Under wxWidgets 3.0, you may use

wxString::ToStdString()

References


  1. Converting_everything_to_and_from_wxString.pdf