printing Unicode characters C++

后端 未结 3 1234
鱼传尺愫
鱼传尺愫 2020-12-10 15:28

I\'m trying to write a simple command line app to teach myself Japanese, but can\'t seem to get Unicode characters to print. What am I missing?

#include <         


        
3条回答
  •  抹茶落季
    2020-12-10 16:26

    There's a whole article about dealing with Unicode in Windows console

    http://alfps.wordpress.com/2011/11/22/unicode-part-1-windows-console-io-approaches/
    http://alfps.wordpress.com/2011/12/08/unicode-part-2-utf-8-stream-mode/

    Basically, you may implement you own streambuf for std::cout (or std::wcout) in terms of WriteConsoleW and enjoy writing UTF-8 (or whatever Unicode you want) to Windows console without depending on locales, console code pages and even without using wide characters.
    It may not look very straightforward, but it's convenient and reusable solution, which is also able to give you a portable utf8-everywhere style user code. Please, don't beat me for my English :)

提交回复
热议问题