How to best deal with Windows' 16-bit wchar_t ugliness?

后端 未结 2 360
暗喜
暗喜 2020-12-20 01:37

I\'m writing a wrapper layer to be used with mingw which provides the application with a virtual UTF-8 environment. Functions which deal with filenames are wrappers which co

2条回答
  •  悲哀的现实
    2020-12-20 02:04

    If you are on windows, you convert between UTF-16 and UTF-8 a whole string at a time using MultiByteToWideChar and WideCharToMultiByte.

    While the default mode in GCC is a 32bit wchar_t there are compile switches that change that, and more generally the c & c++ specs don't specify the size of wchar_t - in fact wchar_t can be the same size as char.

    If you want to avoid using Windows APIs (in your windows wrapper code!?) then use mbstowcs to convert an entire string at a time.

提交回复
热议问题