Page 1 of 1
Convert wxString to Ogre::String
Posted: Sun Apr 27, 2008 4:53 pm
by capture
I am working on a very simple world editor, just something that allows me to load a dotScene and select options. I am using wxWidgets and luke's dotsceneloader from the wiki.
The only problem is that I use wxWidgets to select the file, which returns the path to the file in a wxString. How would I then pass this to the dotsceneloader?
Posted: Mon Apr 28, 2008 2:46 am
by Game_Ender
Ogre::String is just a typedef of std::string, so just look up in the wxWidgets docs how to convert a wxString to a std::string. The first step is probably conversion to a char*.
Posted: Mon Apr 28, 2008 2:56 pm
by CABAListic
wxWidget's disregarding of STL is a huge pain in the ass, imho. Converting wxString to std::string is just one of it. But anyway, here are two quick helper functions to do it:
Code: Select all
inline wxString conv(const std::string& s)
{
return wxString(s.c_str(), wxConvUTF8);
}
inline std::string conv(const wxString& s)
{
return std::string(s.mb_str(wxConvUTF8));
}
You might want to change the encoding to suit your needs, though UTF-8 should be fine for most cases.
Thank
Posted: Mon Apr 28, 2008 11:08 pm
by capture
Thank you very much, those functions are gold.
