How to display the degrees in the window correctly, i.e. not x ^ 2, but so that the deuce is higher?

1 answer 1

First, you need to configure the correct Unicode output. How to do this is described in this question .

Having output in Unicode, it is easy to look at the numbers of Unicode characters, and write the transcoding function. For example, such:

wchar_t digitToSuperscript(unsigned int digit) { if (digit >= 10) throw std::out_of_range("digit"); switch (digit) { case 1: return 0x00B9; case 2: return 0x00B2; case 3: return 0x00B3; default: return 0x2070 + digit; } } 

(Well, or if you prefer, lookup in a table of 10 items.)

We try:

 #include "stdafx.h" #include <iostream> #include <io.h> #include <fcntl.h> #include <stdexcept> wchar_t digitToSuperscript(unsigned int digit) { if (digit >= 10) throw std::out_of_range("digit"); switch (digit) { case 1: return 0x00B9; case 2: return 0x00B2; case 3: return 0x00B3; default: return 0x2070 + digit; } } int wmain(int argc, wchar_t* argv[]) { _setmode(_fileno(stdout), _O_U16TEXT); _setmode(_fileno(stdin), _O_U16TEXT); _setmode(_fileno(stderr), _O_U16TEXT); std::wcout << L"x"; for (int d = 0; d < 10; d++) std::wcout << digitToSuperscript(d); return 0; } 

Result:

picture

  • And there are no big 9 degrees? Or just other codes? - genius
  • @genius: No, print one digit at a time. - VladD