首页 / 🌊 灌水乐园 / <p>#include<br /> 使用
🌊 灌水乐园

<p>#include<br /> 使用命名空间标准;<br /> 虚无 print_utf8(无符...

#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; } 

💬 全部评论 2

共 1 条 · 按楼层排序
登录 注册 后即可发表评论
董昭霖 楼主 Lv.1 初筑者
29天前
#1 楼
<p>#include &lt;iostream&gt;</p><p>using namespace std;</p><p>void print_utf8(unsigned int codepoint)</p><p>{</p><p> if (codepoint &lt;= 0x7F)</p><p> {</p><p> cout &lt;&lt; static_cast&lt;char&gt;(codepoint);</p><p> }</p><p> else if (codepoint &lt;= 0x7FF)</p><p> {</p><p> cout &lt;&lt; static_cast&lt;char&gt;(0xC0 | ((codepoint &gt;&gt; 6) & 0x1F));</p><p> cout &lt;&lt; static_cast&lt;char&gt;(0x80 | (codepoint & 0x3F));</p><p> }</p><p> else if (codepoint &lt;= 0xFFFF)</p><p> {</p><p> cout &lt;&lt; static_cast&lt;char&gt;(0xE0 | ((codepoint &gt;&gt; 12) & 0x0F));</p><p> cout &lt;&lt; static_cast&lt;char&gt;(0x80 | ((codepoint &gt;&gt; 6) & 0x3F));</p><p> cout &lt;&lt; static_cast&lt;char&gt;(0x80 | (codepoint & 0x3F));</p><p> }</p><p>}</p><p>int main()</p><p>{</p><p> long long total = 0;</p><p> const unsigned int start = 0x4E00;</p><p> const unsigned int end = 0x9FFF;</p><p> for (unsigned int ch = start; ch &lt;= end; ch++)</p><p> {</p><p> total++;</p><p> print_utf8(ch);</p><p> }</p><p> cout &lt;&lt; "\n\n全部Unicode标准汉字输出完毕,总数量:" &lt;&lt; total &lt;&lt; endl;</p><p> return 0;</p>}
👍 0 💰 打赏