Writing Unicode Characters to an OStream

后端 未结 2 1747
盖世英雄少女心
盖世英雄少女心 2020-12-21 00:50

I\'m working with unicode/wide characters and I\'m trying to create a toString method (Java ::toString equiv). Will ostream handle wide characters, if so is there a way to w

2条回答
  •  囚心锁ツ
    2020-12-21 01:30

    Wide strings are non-portable and better be avoided in C++. They can be UTF-16, UTF-32 or even non-Unicode depending on platform.

    The common approach in C++ is to use UTF-8 encoded multibyte char strings internally and, if necessary, do transcoding at system boundaries. Most modern systems such as Linux and macOS work well with UTF-8 so passing them to an output stream works. Windows is the most problematic because of legacy code pages. You can use Boost Nowide or the {fmt} library for portable UTF-8 output.

    Disclaimer: I'm the author of {fmt}.

提交回复
热议问题