我对编程相当陌生,但它好像π(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