如何打印 unicode 代码点
How to print unicode codepoint?
如何在 Linux 上以 C++ (gcc/clang) 将 unicode 代码点打印为 unicode 字符?假设我有这样的东西:
typedef uint32_t codepoint;
codepoint cp = somefunction();
如何将 cp 打印为单个 unicode 字符?我有en_US。UTF-8 语言环境。
我已经搜索过了,我试过:wcout,wstring,wchar_t,setlocale,codecvt(gcc中不存在)。
GNU中的std::wcout
有点怪癖:虽然与C stdio同步,但C++和C I/O子系统都需要单独本地化:
所以要么不同步
#include <iostream>
#include <cstdint>
#include <locale>
int main()
{
std::uint32_t n = 0x98A8;
std::wcout.sync_with_stdio(false);
std::wcout.imbue(std::locale("en_US.utf8"));
std::wcout << wchar_t(n) << 'n';
}
http://coliru.stacked-crooked.com/a/13b718ae11fa539e
或同时本地化两者
#include <iostream>
#include <cstdint>
#include <locale>
#include <clocale>
int main()
{
std::uint32_t n = 0x98A8;
std::setlocale(LC_ALL, "en_US.utf8");
std::wcout.imbue(std::locale("en_US.utf8"));
std::wcout << wchar_t(n) << 'n';
}
http://coliru.stacked-crooked.com/a/80b7d4547e1184ad
相关文章:
- Unicode - ICU 库 - 获取 UnicodeString 中的代码点计数
- C++基础知识(使用其他方法(Unicode?)的相同代码)
- C++Unicode:字节、代码点和图形
- 如何处理C 中Unicode支持涉及的代码重复
- 如何从 UTF-8 字符串的每个字符中获取 UNICODE 代码
- 从ASCII到Unicode字符代码的转换(FreeType2)
- 如何打印 unicode 代码点
- 使用 C++ 测试 Unicode 代码点是否在 ISO-8859-5 集中
- MultiByteToWideChar 用于 Unicode 代码页 1200、1201、12000、12001
- 如何在c++中将unicode代码点转换为utf-8
- 如何使用特定的 Unicode 代码点 RTRIM wchar_t
- 在哪里可以找到 C++ ICU Unicode 的可能代码页参数值
- 匹配 Unicode 代码点的约定,同时遵守 BOM
- 使用json_write()时有两个unicode代码点
- 在C++11中,如何打印给定Unicode代码的字符
- 如何读取具有Unicode代码的文本文件
- 如何将十六进制代码值转换为unicode字符
- 如何使用ICU将Unicode代码点转换为C++中的字符
- Unicode 代码指向字节并反向:如何在C++中做到这一点
- 获取unicode代码点的大写或小写(如uint32_t)