How do I get STL std::string to work with unicode on windows?

前端 未结 9 2089
猫巷女王i
猫巷女王i 2021-02-04 13:29

At my company we have a cross platform(Linux & Windows) library that contains our own extension of the STL std::string, this class provides all sort of functionality on top

9条回答
  •  醉梦人生
    2021-02-04 14:11

    In the Windows API and C runtime library, char* parameters are interpreted as being encoded in the "ANSI" code page. The problem is that UTF-8 isn't supported as an ANSI code page, which I find incredibly annoying.

    I'm in a similar situation, being in the middle of porting software from Windows to Linux while also making it Unicode-aware. The approach we've taken for this is:

    • Use UTF-8 as the default encoding for strings.
    • In Windows-specific code, always call the "W" version of functions, converting string arguments between UTF-8 and UTF-16 as necessary.

    This is also the approach Poco has taken.

提交回复
热议问题