Std :: string, wstring, clarification by u16 / 32string

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

I also read that most (if not all) linux distributions use char for all and all strings, both ASCII and UTF, where Windows is the main OS that uses wchar_t .

However, there are a few more types of strings that I want to get right 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 , std::wstring functionally equivalent to std::u16string , as well as platforms with sizeof(wchar_t) == 4 and std::u32string ?

+6
source share
1 answer

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

This means that wstring will probably keep the same data as u16string or u32string , but we don’t know which one. And it is allowed that some odd implementation makes them different, since the size and encoding of old char types are simply not defined by the standard.

+14
source

All Articles