Windows console does not display square root sign

For a console application, I need to display the symbol: √
When I try to just output it using:
std::cout << '√' << std::endl; or
std::wcout << '√' << std::endl; ,
he displays instead the number 14846106 .

I tried to find the answer and found some recommendations: std::cout << "\xFB" << std::endl; and
std::cout << (unsigned char)251 << std::endl;
which both display superscript 1.

This is a Windows console with Lucida font. I tried this with different character pages and always got the same superscript. When I try to find its value via getchar() or cin , the character is converted to uppercase V However, I am sure that it can display this symbol by simply inserting it. Is there an easy way to display Unicode characters?

+4
source share
1 answer

Actually, "\xFB" or (unsigned char)251 matches and matches the root character √ ... but not in the Lucida font and other ASCII font tables where it is ¹ (superscript 1).

Switching to Unicode with STL is an option, but I doubt it will work on Windows ...

 #include <iostream> #include <locale.h> int main() { std::locale::global(std::locale("en_US.UTF8")); std::wcout.imbue(std::locale()); wchar_t root = L'√'; std::wcout << root << std::endl; return 0; } 

Since this does not suit you, here is the Unicode portable library: http://site.icu-project.org/

+1
source

Source: https://habr.com/ru/post/1494860/


All Articles