Output unicode strings in Windows console app

后端 未结 11 958
花落未央
花落未央 2020-11-21 11:20

Hi I was trying to output unicode string to a console with iostreams and failed.

I found this: Using unicode font in c++ console app and this snippet work

11条回答
  •  再見小時候
    2020-11-21 11:50

    Recenly I wanted to stream unicode from Python to windows console and here is the minimum I needed to make:

    • You should set console font to the one covering unicode symbols. There is not a wide choise: Console properties > Font > Lucida Console
    • You should change the current console codepage: run chcp 65001 in the Console or use the corresponding method in the C++ code
    • write to console using WriteConsoleW

    Look through an interesing article about java unicode on windows console

    Besides, in Python you can not write to default sys.stdout in this case, you will need to substitute it with something using os.write(1, binarystring) or direct call to a wrapper around WriteConsoleW. Seems like in C++ you will need to do the same.

提交回复
热议问题