gpt4 book ai didi

c++ - 有关C++中char数据类型的问题

转载 作者:行者123 更新时间:2023-12-02 10:19:49 25 4
gpt4 key购买 nike

我了解'char'数据类型用于存储单个字符并使用1个字节的事实,但是char16_t,char32_t和wchar_t分别用于什么呢?毕竟,我们只需要存储一个字符

最佳答案

关于char16_tchar32_t,引用Microsoft article:

The char16_t and char32_t types represent 16-bit and 32-bit wide characters, respectively. Unicode encoded as UTF-16 can be stored in the char16_t type, and Unicode encoded as UTF-32 can be stored in the char32_t type. Strings of these types and wchar_t are all referred to as wide strings, though the term often refers specifically to strings of wchar_t type.



对于 wchar_t:

The wchar_t type is an implementation-defined wide character type. In the Microsoft compiler, it represents a 16-bit wide character used to store Unicode encoded as UTF-16LE, the native character type on Windows operating systems. The wide character versions of the Universal C Runtime (UCRT) library functions use wchar_t and its pointer and array types as parameters and return values, as do the wide character versions of the native Windows API.



因此,不能仅仅将它们说成一个角色。如上所述,类型与编码不同。

例如,以 u编码的字符 char16_t(U + 0075)被存储为 feff0075

关于c++ - 有关C++中char数据类型的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60680550/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com