0

Lead by this page(How to print Unicode character in C++?), I can print Russian "ф".but when try to print "m³"(\u 33a5), I got a "?".

enter image description here

Please anyone can help me.

Community
  • 1
  • 1
Simson
  • 13
  • 8

2 Answers2

1

Console normally does not support displaying unicode characters. Try solution for this question Unicode characters in Windows command line - how?

Community
  • 1
  • 1
zmechanic
  • 1,842
  • 21
  • 27
  • 1
    Yes, as Windows normally doesn't support Unicode :) – Ruslan Osmanov May 05 '16 at 14:09
  • 1
    @RuslanOsmanov: Windows itself supports Unicode – it uses [UTF-16](https://en.wikipedia.org/w/index.php?title=UTF-16&oldid=717435654) extensively in many of its APIs. cmd, however, defaults to a legacy code page (the precise page is determined by your locale) and requires an explicit switch into Unicode mode. – Benjamin Barenblat May 05 '16 at 14:15
  • so does it means that if m^3 is output into a file but not console, everything will be right? – Simson May 05 '16 at 14:27
  • @BenjaminBarenblat the command window also supports full UTF-16, if you use the console API to interact with it (and the selected font contains the characters you need). It's only the character-based interface that suffers. Unfortunately the whole point of having a command window is to use the character-based interface. – Mark Ransom May 05 '16 at 15:11
1

Try this:

#include <iostream>
#include <fcntl.h>
#include <io.h>

int main()
{
    _setmode(_fileno(stdout), _O_U16TEXT);
    std::wcout << L"m\u00B3" << std::endl;
    return 0;
}
Ales
  • 11
  • 2