I'm developing a game (actually I'm porting it from Gosu to SFML) in C++. I'm using GNU Gettext as the i18n system. As you know, gettext returns char *
strings using the local encoding, usually UTF8. The problem is that I need to use wide strings for SFML to recognize the special characters such as áéíüñ
.
So the question would be: how do I create a proper wstring
from the output of gettext? It would be great if there were some kind of wchar_t * w_gettext()
function, but there's not. I have tried some options, such as creating a wstring
from the original string
by passing the iterators, but obviously it does not work.
To convert between the system's narrow, multibyte encoding and its wide character set (agnostic of any encoding specifics), use the mbstowcs()
and wcstombs()
standard C functions, found in <cwchar>
. Here's a previous post of mine on the subject, and here's some sample code.