std::string, wstring, u16/32string clarification

本小妞迷上赌 提交于 2019-12-19 16:57:31

问题


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

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.

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:

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?


回答1:


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.

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.



来源:https://stackoverflow.com/questions/14438129/stdstring-wstring-u16-32string-clarification

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!