I need to convert a std::string to wchar_t*.
Because I want to use guiEnv->addStaticText(...) to print this string on the screen.
How can I do this?
std::string to wchar_t*
-
- Admin
- Posts: 14143
- Joined: Wed Apr 19, 2006 9:20 pm
- Location: Oldenburg(Oldb), Germany
- Contact:
Re: std::string to wchar_t*
core::stringw(mystdstring.c_str()).c_str() if you don't want to rely on the correct conversion functions for wide chars
Re: std::string to wchar_t*
If you want to stick with C++ STL, you may also do this;
From basic string:
You may also reverse it, replacing std::wstring with std::string.
From basic string:
Code: Select all
std::string other("foobar");
const std::wstring& ws = std::wstring(other.begin(), other.end());
const wchar_t* const wchr = wc.c_str();
Re: std::string to wchar_t*
@kekar> interesting way of doing it. Is that always safe ? If you confirm it I might give up on us http://utfcpp.sourceforge.net/ which I currently use and also use iterators.
which means some chars are going to be misinterpreted ? What would be the correct irrlicht way (if any) ?core::stringw(mystdstring.c_str()).c_str() if you don't want to rely on the correct conversion functions for wide chars
Using trunk with mingw/gcc 4.6, Windows 7 64 bits driver opengl
-
- Admin
- Posts: 14143
- Joined: Wed Apr 19, 2006 9:20 pm
- Location: Oldenburg(Oldb), Germany
- Contact:
Re: std::string to wchar_t*
Actually, for this way it should be safe. All chars should be representable as wchars. So you have no loss. But the other way round will of course make only direct casts from wide to normal chars. And this will break on all extended chars. Don't know how the STL would do this, but in C you have the mb methods for conversion.