如何从数字中获取 Unicode 字符?

How can I get a Unicode character from a number?

我是 C++ 的新手,很抱歉,如果这很明显。

如何从数字中获取字符? 我有以下代码:

for (int i = 0; i < 500; i++) {
    cout << i;
}

它应该获取 Unicode 字典中的前 500 个字符。 我知道在javascript中是String.fromCodePoint(i)。什么是 C++ 等价物?

改用wchar_t

for (wchar_t i = 0; i < 500; i++) {
    wcout << i;
}

如果您使用的是 C++11 或更高版本,您也可以使用 char16_t and char32_t

但是您仍然需要一个功能强大的终端,还需要设置正确的代码页以获得预期的输出。在 Linux 上它非常简单,但如果您使用(较旧的)Windows 则要复杂得多。参见 Output unicode strings in Windows console app