std::wstring
holds wchar_t
elements, and wchar_t
is a different size across platforms (2 bytes on Windows, 4 bytes elsewhere), and as such std::wstring
uses different encodings across platforms (UTF-16 on Windows, UTF-32 elsewhere). Just as std::string
can hold different 8bit encodings (UTF-8, ISO-8859-x, Windows-125x, etc).
So, you are not asking how to convert between std::string
and std::wstring
themselves, but how to convert between different encodings. And the fact is, C++ simply doesn’t support that natively. C++11 tried to address that with std::codecvt
and std::wstring_convert
, but they are limited, and as you have noted have since been deprecated in C++17, with no replacement is sight.
So, you best options is to use 3rd party cross-platform libraries, such as ICU, ICONV, etc.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…