我對編程相當陌生,但它好像π(pi)
符號不在ASCII
處理的標準輸出集合中。在C++ win32控制檯應用程序中輸出unicode符號π和≈
我想知道是否有辦法讓控制檯輸出π
符號,以便表達關於某些數學公式的確切答案。
我對編程相當陌生,但它好像π(pi)
符號不在ASCII
處理的標準輸出集合中。在C++ win32控制檯應用程序中輸出unicode符號π和≈
我想知道是否有辦法讓控制檯輸出π
符號,以便表達關於某些數學公式的確切答案。
Microsoft CRT不是非常精通Unicode的,因此可能需要繞過它並直接使用WriteConsole()
。我假設你已經編譯爲Unicode,否則你需要明確使用WriteConsoleW()
我不太確定任何其他方法(如使用STL的方法),但可以使用WriteConsoleW在Win32上執行此操作:
HANDLE hConsoleOutput = GetStdHandle(STD_OUTPUT_HANDLE);
LPCWSTR lpPiString = L"\u03C0";
DWORD dwNumberOfCharsWritten;
WriteConsoleW(hConsoleOutput, lpPiString, 1, &dwNumberOfCharsWritten, NULL);
我在這個學習階段,所以糾正我,如果我得到錯誤的東西。
看起來這是一個三個步驟的過程:
你現在應該能夠搖滾那些時髦的åäös。
例子:
#include <iostream>
#include <string>
#include <io.h>
// We only need one mode definition in this example, but it and several other
// reside in the header file fcntl.h.
#define _O_WTEXT 0x10000 /* file mode is UTF16 (translated) */
// Possibly useful if we want UTF-8
//#define _O_U8TEXT 0x40000 /* file mode is UTF8 no BOM (translated) */
void main(void)
{
// To be able to write UFT-16 to stdout.
_setmode(_fileno(stdout), _O_WTEXT);
// To be able to read UTF-16 from stdin.
_setmode(_fileno(stdin), _O_WTEXT);
wchar_t* hallå = L"Hallå, värld!";
std::wcout << hallå << std::endl;
// It's all Greek to me. Go UU!
std::wstring etabetapi = L"η β π";
std::wcout << etabetapi << std::endl;
std::wstring myInput;
std::wcin >> myInput;
std:: wcout << myInput << L" has " << myInput.length() << L" characters." << std::endl;
// This character won't show using Consolas or Lucida Console
std::wcout << L"♔" << std::endl;
}
什麼是你的控制檯字體?只需使用CMD.EXE來檢查。它不同於Windows版本,可以自定義。 – MSalters