简体   繁体   中英

Windows console does not display square root sign

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

I've tried searching for an answer and have found several recommendations of the following:
std::cout << "\\xFB" << std::endl; and
std::cout << (unsigned char)251 << std::endl;
which both display a superscript 1.

This is using the Windows console with Lucida font. I've tried this with various character pages and always get the same superscript 1. When I try to find its value through getchar() or cin , the symbol is converted into the capital letter V . I am, however, sure that it can display this character simply by pasting it in. Is there an easy way of displaying Unicode characters?

Actually "\\xFB" or (unsigned char)251 are the same and do correspond to the root symbol √... but not in the Lucida font and other typefaces ASCII table , where it is an ¹ (superscript 1).

Switching to Unicode with the STL is a possibility, but I doubt it will run 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 will not satisfy you, here a portable Unicode library: http://site.icu-project.org/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM