“UTF-16”和“UTF-16”有什么区别?和“std::wstring”?

发布于 2024-10-03 10:00:25 字数 24 浏览 1 评论 0 原文

这两种字符串存储格式有什么区别吗?

Is there any difference between these two string storage formats?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

难理解 2024-10-10 10:00:25

std::wstringwchar_t 的容器。 wchar_t 的大小未指定 - Windows 编译器倾向于使用 16 位类型,Unix 编译器倾向于使用 32 位类型。

UTF-16 是一种以 16 位序列对 Unicode 代码点序列进行编码的方法整数。

使用 Visual Studio,如果您使用不包含 ) %28Unicode%29#Basic_Multilingual_Plane" rel="noreferrer">BMP,您最终会得到 UTF-16,但这两个概念大多数情况下是不相关的。如果您使用 BMP 之外的字符,std::wstring 将不会翻译 代理对为您转换为 Unicode 代码点,即使 wchar_t 是 16 位。

std::wstring is a container of wchar_t. The size of wchar_t is not specified—Windows compilers tend to use a 16-bit type, Unix compilers a 32-bit type.

UTF-16 is a way of encoding sequences of Unicode code points in sequences of 16-bit integers.

Using Visual Studio, if you use wide character literals (e.g. L"Hello World") that contain no characters outside of the BMP, you'll end up with UTF-16, but mostly the two concepts are unrelated. If you use characters outside the BMP, std::wstring will not translate surrogate pairs into Unicode code points for you, even if wchar_t is 16 bits.

怪异←思 2024-10-10 10:00:25

UTF-16 是一种特定的 Unicode 编码。 std::wstring 是一个字符串实现,它使用 wchar_t 作为其存储每个字符的基础类型。 (相反,常规 std::string 使用 char)。

wchar_t 使用的编码确实不一定必须是 UTF-16,例如也可以是 UTF-32。

UTF-16 is a specific Unicode encoding. std::wstring is a string implementation that uses wchar_t as its underlying type for storing each character. (In contrast, regular std::string uses char).

The encoding used with wchar_t does not necessarily have to be UTF-16—it could also be UTF-32 for example.

恏ㄋ傷疤忘ㄋ疼 2024-10-10 10:00:25

UTF-16 是一种以 16 位元素表示的文本概念,但实际的文本字符可能由多个元素组成

std​​::wstring 只是这些元素的集合,并且是一个主要与它们的存储有关的类。

wstring、wchar_t 中的元素至少为 16 位,但也可以为 32 位。

UTF-16 is a concept of text represented in 16-bit elements but an actual textual character may consist of more than one element

std::wstring is just a collection of these elements, and is a class primarily concerned with their storage.

The elements in a wstring, wchar_t is at least 16-bits but could be 32 bits.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文