#include
使用命名空间标准;
虚无 print_utf8(无符号 int 代码点)
{
如果(码点 <= 0x7F)
{
cout << static_cast(代码点);
}
否则如果(码点 <= 0x7FF)
{
考特<< static_cast(0xC0 |((代码点>> 6) & 0x1F));
考特<< static_cast(0x80 |(codepoint & 0x3F));
}
否则如果(码点 <= 0xFFFF)
{
考特<< static_cast(0xE0 |((代码点>> 12)& 0x0F));
考特<< static_cast(0x80 |((代码点>> 6) & 0x3F));
考特<< static_cast(0x80 |(codepoint & 0x3F));
}
}
int main()
{
长长总和 = 0;
cont unsigned int start = 0x4E00;
cont unsigned int end = 0x9FFF;
对于(无符号整数 ch = 开始;ch <= 结束;ch++)
{
total++;
print_utf8(ch);
}
cout << “\n\n全部Unicode标准汉字输出完毕,总数量:” << total << endl;
返回0;
} <iostream> <char>`` <char> <char>`` <char> <char>`` <char>#include <iostream> using namespace std; void print_utf8(unsigned int codepoint) { if (codepoint <= 0x7F) { cout << static_cast<char>(codepoint); } else if (codepoint <= 0x7FF) { cout << static_cast<char>(0xC0 | ((codepoint >> 6) & 0x1F)); cout << static_cast<char>(0x80 | (codepoint & 0x3F)); } else if (codepoint <= 0xFFFF) { cout << static_cast<char>(0xE0 | ((codepoint >> 12) & 0x0F)); cout << static_cast<char>(0x80 | ((codepoint >> 6) & 0x3F)); cout << static_cast<char>(0x80 | (codepoint & 0x3F)); } } int main() { long long total = 0; const unsigned int start = 0x4E00; const unsigned int end = 0x9FFF; for (unsigned int ch = start; ch <= end; ch++) { total++; print_utf8(ch); } cout << "\n\n全部Unicode标准汉字输出完毕,总数量:" << total << endl; return 0; }
🌊 灌水乐园