1

I have written the following code, but when I compile and run this program in the console of windows, it doesn't show the characters correctly. What is the problem?

#include <iostream>

auto main(int argc, char* argv[]) -> decltype(0) {

    char const u8[]{ u8"Hello, ☃!" };
    std::cout << "UTF 8: " << u8 << std::endl;

    char16_t const u16[]{ u"Hello, ☃!" };
    std::cout << "UTF 16: " << u16 << std::endl;

    char32_t const u32[]{ U"Hello, ☃!" };
    std::cout << "UTF 32: " << u32 << std::endl;

    return 0;
}

Output of the program:

UTF 8: Hello, Γÿâ!
UTF 16: 0053F790
UTF 32: 0053F750
alinsoar
  • 15,386
  • 4
  • 57
  • 74
  • `std::cout` in general can only be used to print ascii characters. If you want to print Unicode a better idea would be to use native API. Or just meddle with standard output modes. Note that you will also need to make sure that console uses font that contains those fancy characters. – user7860670 Jun 14 '19 at 08:35
  • 2
    Possible duplicate: https://stackoverflow.com/questions/2492077/output-unicode-strings-in-windows-console-app/9051543 –  Jun 14 '19 at 08:53
  • 1
    If you succeed in writing "☃" to the console, it will likely be displayed as the font's default glyph, typically an empty rectangle. Displaying the full range of Unicode requires font fallback support, which the console host doesn't support. Microsoft's upcoming terminal app will, and I think they eventually plan to support it in the console. – Eryk Sun Jun 14 '19 at 18:31

0 Answers0