栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

【字符集八】char8

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

【字符集八】char8

一、vs编译器如何支持C++20标准

参考:

二、简介
  • char :
    c++中的关键字,占用1个字节。

  • wchar_t
    https://www.educba.com/c-plus-plus-wchar_t/

  • char16_t、char32_t
    https://en.cppreference.com/w/c/string/multibyte/char16_t

  • char8_t:c++20标准中新增加的关键字。
    https://open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0482r6.html

三、demo
#include 
using namespace std;
int main()
{
    //char* loc = setlocale(LC_ALL,".65001");

    char ch[] = "我";
    char8_t ch8[] = u8"我";
    wchar_t wch[] = L"我";
    char16_t ch16[] = u"我";
    char32_t ch32[] = U"我";

    cout << &ch< 

输出:

00B7F83C
00B7F830
00B7F824
00B7F818
00B7F808
ch:0xffffffe60xffffff880xffffff910
ch8:0xffffffe60x880x910
wch:0x6211
ch16:0x6211
ch32:0x6211

utf-8的中文是一个汉字占三个字节长度吗?

四、分析
  • char和char8_t中存的数字为:e6 88 91。代表汉字我的字符编码,三个字节,计算方式参考字符集vs字符编码。安装文章中的计算方式,换算后也是等于62 11.
  • wchar_t、char16_t、char_32t中存的数字为:62 11。其中6211为Unicode的汉字”我"的字符编码;参见汉字的宽字符码和多字节码分别是多少
五、c++20标准:char8_t不可以输出

Recap
char8_t can not hold a full range of utf-8 glyphs. utf-8 glyphs can be up to 4 bytes. char8_t holds up to 1 byte.
char8_t stream out is expressly forbidden in C++20
for utf-8 compatibility while in VStudio use char and the /utf-8 switch
in case you really want C++20 way of transforming to/from char8_t, you need to use … AFAIK not yet fully implemented in any of the 3, as required by the standard

参见:C++20 char8_t, the Boson

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/948123.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号