question on std::string and wxString Topic is solved

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
spectrum
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 207
Joined: Sat Jul 21, 2007 12:17 pm

question on std::string and wxString

Post by spectrum »

hello all,

sorry for the n'th thread on this, i've read some threads on it, but i was look for a suggestion about the best way to go writing portable code.

I was looking for the best way to align std::string to wxString.

I've started to work with wxWidgets 2.8 under windows. I've soon noticed that wxString and std::string, even if are 2 different objects, are both usable in the same way, almost for my development point of view.

So i've used some old cpp modules i've written with std::string, and also std::string somewhere, and wxString in other places, in a mixed fashon.

Then i've installed wxwidgets 2.8 on linux debian, and i've soon discovered that the default installation of wxgtk is unicode.

wxString so here is unicode based, and obviously the same code don't compile anymore. As mentioned in other thread, in this case std::wstring should be intercangheable.

For now i've solved using this syntax.

Code: Select all

wxString(myStdString.c_str(), wxConvUTF8));
I'm going to introduce this conversion everywhere i can't avoid the use of std::string.

I would mantain some old modules using the std templates, just to be compiled without wxWidgets library when i need.

Is this practice an acceptable way to go ? Is this conversion passage heavy in some way even if the string is already ascii based ?

Thanks
angelo
spectrum
Sof_T
Can't get richer than this
Can't get richer than this
Posts: 864
Joined: Thu Jul 28, 2005 9:48 pm
Location: New Forest, United Kingdom
Contact:

Post by Sof_T »

I believe you can recompile the wxWidgets library to use wxString based on std::string. I can't remember which flag you need at compile time, but it is clear in the documentation.

Sof.T
The home of Sof.T http://www.sof-t.site88.net/
Author of Programming with wxDevC++
http://sourceforge.net/projects/wxdevcpp-book/
spectrum
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 207
Joined: Sat Jul 21, 2007 12:17 pm

Post by spectrum »

thanks,

i've found that with 'wx-config --unicode=no' under linux i have solved all my issues without the need of conversions.

Thanks, angelo
spectrum
Post Reply