How to Output Unicode Strings on the Windows Console

后端 未结 4 1217
独厮守ぢ
独厮守ぢ 2020-11-28 13:48

there are already a few questions relating to this problem. I think my question is a bit different because I don\'t have an actual problem, I\'m only asking out of academic

4条回答
  •  有刺的猬
    2020-11-28 14:30

    Several points:

    1. One important difference between Windows "WriteConsoleW" and printf is that WriteConsoleW looks at console as GUI rather them text stream. For example if you use it and use pipe you would not capture output.
    2. I would never said that code-pages are obsolete. Maybe windows developers would like them to be so, but they never would be. All world, but windows api, uses byte oriented streams to represent data: XML, HTML, HTTP, Unix, etc, etc use encodings and most popular and most powerful one is UTF-8. So you may use Wide strings internally but in external world you'll need something else.

      Even when you print wcout << L"Hello World" << endl it is converted under the hood to byte oriented stream, on most systems (but windows) to UTF-8.

    3. My personal opinion, Microsoft did mistake when changed their API in every place to wide instead of supporting UTF-8 everywhere. Of course you may argue about it. But in fact you have to separate text and byte oriented streams and convert between them.

提交回复
热议问题