Mic*_*ler 4 unicode macos char
我正在尝试使用 unicode 字符在终端中进行一些简单的框画。但是我注意到 wcout 不会为框绘图字符输出任何内容,甚至不会输出占位符。所以我决定写下面的程序,找出支持哪些unicode字符,发现wcout拒绝输出255以上的任何东西。有什么我必须做的事情才能使wcout正常工作?为什么无法访问任何扩展的 unicode 字符?
#include <wchar.h>
#include <locale>
#include <iostream>
using namespace std;
int main()
{
for (wchar_t c = 0; c < 0xFFFF; c++)
{
cout << "Iteration " << (int)c << endl;
wcout << c << endl << endl;
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我不推荐使用,wcout因为它不可移植、效率低下(总是执行转码)并且不支持所有 Unicode(例如代理对)。
相反,您可以使用开源 {fmt} 库来可移植地打印 Unicode 文本,包括框绘图字符,例如:
#include <fmt/core.h>
int main() {
fmt::print("??????????????????????\n"
"? Hello, world! ?\n"
"??????????????????????\n");
}
Run Code Online (Sandbox Code Playgroud)
打印(https://godbolt.org/z/4EP6Yo):
??????????????????????
? Hello, world! ?
??????????????????????
Run Code Online (Sandbox Code Playgroud)
免责声明:我是 {fmt} 的作者。
| 归档时间: |
|
| 查看次数: |
292 次 |
| 最近记录: |