我对编程很新,但似乎π(pi)
符号不在ASCII
处理的标准输出集中。
我想知道是否有办法让控制台输出π
符号,以便表达有关某些数学公式的确切答案。
答案 0 :(得分:3)
我不确定任何其他方法(例如那些使用STL的方法)但你可以使用WriteConsoleW在Win32上执行此操作:
HANDLE hConsoleOutput = GetStdHandle(STD_OUTPUT_HANDLE);
LPCWSTR lpPiString = L"\u03C0";
DWORD dwNumberOfCharsWritten;
WriteConsoleW(hConsoleOutput, lpPiString, 1, &dwNumberOfCharsWritten, NULL);
答案 1 :(得分:1)
Microsoft CRT不是非常精通Unicode,因此可能需要绕过它并直接使用WriteConsole()
。我假设您已经为Unicode编译,否则您需要明确使用WriteConsoleW()
答案 2 :(得分:1)
我正处于学习阶段,所以如果我出错了,请纠正我。
这似乎是一个三步过程:
你现在应该能够撼动那些时髦的åäö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;
}