Cross-platform strings (and Unicode) in C++

前端 未结 4 1096
半阙折子戏
半阙折子戏 2020-12-25 08:35

So I\'ve finally gotten back to my main task - porting a rather large C++ project from Windows to the Mac.

Straight away I\'ve been hit by the problem where wchar_t

4条回答
  •  臣服心动
    2020-12-25 09:06

    Always use a protocol defined to the byte when a file or network connection is involved. Do not rely on how a C++ compiler stores anything in memory. For Unicode text, this means choosing both an encoding and a byte order (okay, UTF-8 doesn't care about byte order). Even if the platforms you currently want to support have similar architectures, another popular platform with different behavior or even a new OS for one of your existing platforms will likely come along, and you'll be glad you wrote portable code.

提交回复
热议问题