How to deal with Unicode strings in C/C++ in a cross-platform friendly way?

后端 未结 3 767
情话喂你
情话喂你 2021-01-05 09:31

On platforms different than Windows you could easily use char * strings and treat them as UTF-8.

The problem is that on Windows you are required to acce

3条回答
  •  甜味超标
    2021-01-05 09:58

    If you writing portable code:

    1st Never use wchar_t it is nor portable and its encoding is not well defined between platforms (utf-16 windows/utf-32 all others).

    Never use TChar, use plain std::string encoded as UTF-8.

    When dealing with Brain Damaged Win32 API just convert UTF-8 string to UTF-16 before calling it.

    See https://stackoverflow.com/questions/1049947/should-utf-16-be-considered-harmful as well about how Windows project adopt UTF-8 as main encoding.

提交回复
热议问题