[英]Windows console does not display square root sign
對於控制台應用程序,我需要顯示符號:√
當我嘗試使用以下方法輸出時:
std::cout << '√' << std::endl;
要么
std::wcout << '√' << std::endl;
,
它會輸出數字14846106
。
我試過尋找答案,並找到了以下幾點建議:
std::cout << "\\xFB" << std::endl;
和
std::cout << (unsigned char)251 << std::endl;
兩者都顯示上標1。
這是使用帶有Lucida字體的Windows控制台。 我已嘗試使用各種字符頁面,並始終獲得相同的上標1.當我嘗試通過getchar()
或cin
查找其值時,符號將轉換為大寫字母V
但是,我確信只需將其粘貼即可顯示此字符。是否有簡單的方法顯示Unicode字符?
實際上"\\xFB"
或(unsigned char)251
是相同的並且對應於根符號√...但不是Lucida字體和其他字體ASCII表,其中它是¹(上標1)。
使用STL切換到Unicode是可能的,但我懷疑它會在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;
}
由於這不會讓您滿意,這里有一個可移植的Unicode庫: http : //site.icu-project.org/
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.