Convert wxString to Ogre::String

A place for Ogre users to discuss non-Ogre subjects with friends from the community.
Post Reply
capture
Goblin
Posts: 237
Joined: Sun Nov 20, 2005 2:44 pm

Convert wxString to Ogre::String

Post 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?
User avatar
Game_Ender
Ogre Magi
Posts: 1269
Joined: Wed May 25, 2005 2:31 am
Location: Rockville, MD, USA

Post 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*.
CABAListic
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 2903
Joined: Thu Jan 18, 2007 2:48 pm
x 58
Contact:

Post 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.
capture
Goblin
Posts: 237
Joined: Sun Nov 20, 2005 2:44 pm

Thank

Post by capture »

Thank you very much, those functions are gold. :)
Post Reply