Display Unicode Characters C++/WinRT

Michael Hanson 1 Reputation point
2020-12-21T23:43:36.347+00:00

This question pertains to your online article: Get Started with C++/WinRT (https://learn.microsoft.com/en-us/windows/uwp/cpp-and-winrt-apis/get-started). In order to get the unicode characters to display in the console window, I had to add the following includes: #include <fcntl.h>, and #include <io.h>. I also had to set the console mode using the following line of code: int old = _setmode(_fileno(stdout), _O_U16TEXT);. Am I missing something or is the lesson missing something?

Mike Hanson

Universal Windows Platform (UWP)
C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,761 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Guido Franzke 2,196 Reputation points
    2020-12-22T06:59:02.673+00:00

    Hello,
    has your console the correct output enconding? As far as I know the console starts to output only simple ASCII characters.
    You should change the encoding of the console in your code. Have a look at this:
    how-to-write-unicode-characters-to-the-console
    Regards, Guido


  2. Michael Hanson 1 Reputation point
    2020-12-24T01:29:02.57+00:00

    While reading through the first part of this article at https://learn.microsoft.com/en-us/windows/uwp/cpp-and-winrt-apis/get-started#a-cwinrt-quick-start, the titles would not display on my console window. After researching winrt::hstring, I learned it was UTF-16 based. The console is UTF-8 based. While researching this several articles on the internet said that the font you use to display UTF-16 characters must be a True Type Font. My window is using Consolas. The feed titles would not display.

    After further research, others having the same problem were told to set the console window programatically by using the following line: int old = _setmode(_fileno(stdout), _O_U16TEXT);. I also included fcntl.h and io.h header files. I ran the program and the titles appeared.

    I'm running Windows 10 build 19042.685. Visual Studio 2019 version 16.8.3.

    Because I had to make the changes to the program to get it to work, is the article flawed?

    Please verify.

    Thanks.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.