4

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.

José Tomás Tocino
  • 9,873
  • 5
  • 44
  • 78

2 Answers2

3

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.

Community
  • 1
  • 1
Kerrek SB
  • 464,522
  • 92
  • 875
  • 1,084
1

You can convert your multi-byte UTF-8 string to wide char.

On Windows, use MultiByteToWideChar. On Unix, use libiconv.

Miguel Grinberg
  • 65,299
  • 14
  • 133
  • 152