本文介绍了std :: string,wstring,u16 / 32string澄清的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前理解 std :: string std :: wstring 之间的区别只是缓冲区的类型;分别是 char vs wchar_t

My current understanding of the difference between std::string and std::wstring is simply the buffer's type; namely, char vs wchar_t, respectively.

've也读取大多数(如果不是所有)linux发行版对任何和所有字符串,ASCII和UTF使用 char ,其中Windows是主操作系统, code> wchar_t 。

I've also read that most (if not all) linux distros use char for any and all strings, both ASCII as well as UTF, where Windows is the primary OS that uses wchar_t anymore.

然而,还有更多的字符串类型,我想直接在我脑海中: code> u16string 和 u32string ,分别是具有2字节和4字节缓冲区的字符串。

However, there are a few more string types that I want to get straight in my head: u16string and u32string, which are strings with 2-byte and 4-byte buffers, respectively.

所以,我的问题是这样:

So, my question is this:

的平台上sizeof(wchar_t)== 2 std :: wstring 在功能上等同于 std :: u16string code> sizeof(wchar_t)== 4 和 std :: u32string

On platforms with sizeof(wchar_t) == 2, is std::wstring functionally equivalent to std::u16string, as well as platforms with sizeof(wchar_t) == 4 and std::u32string?

推荐答案

不同之处在于 char wchar_t 的详细信息实现定义,而 char16_t char32_t 的编码由C ++ 11标准显式定义。

The difference is that the details of char and wchar_t are implementation defined, while the encoding of char16_t and char32_t are explicitly defined by the C++11 standard.

这意味着 wstring 可能来存储相同的数据 u16string u32string ,但我们不知道哪一个。并且允许一些奇怪的实现使它们全部不同,因为旧的字符类型的大小和编码只是没有被标准定义。

This means that wstring is likely to store the same data as either u16string or u32string, but we don't know which one. And it is allowed for some odd implementation to make them all different, as the size and encoding of the old char types are just not defined by the standard.

这篇关于std :: string,wstring,u16 / 32string澄清的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 13:16