On Wed, 22 Mar 2017, at 09:49, Mario Emmenlauer wrote:
> I could narrow down the problem, and actually it seems to be mostly
> a complete ignorance on my side about how unicode, utf8, utf16, wchar
> etc work. I was under the (naiive?) assumption that I could convert a
> std::string to std::wstring with the codecvt converter from C++11
> std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>, wchar_t> and
> would just get the same string in a different representation, at least
> for some basic ASCII. This seems far from reality! :-( :-( :-(
>
> In fact, it has nothing to do with Windows. Also on Linux, the following
> does not do what I expect:
>
> std::string vCharStr = "hello world";
> std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>, wchar_t>
> utf8_to_utf16_converter;
> std::wstring vWCharStrFromCharStr =
> utf8_to_utf16_converter.from_bytes(vCharStr);
> std::wcout << "vWCharStrFromCharStr = '" << vWCharStrFromCharStr << "'" <<
> std::endl;
> // shows only unprintable characters
sizeof(wchar_t) is 4 on Linux, so it's not UTF-16. The following works:
std::string vCharStr = "hello world";
std::wstring_convert<std::codecvt_utf8<wchar_t>, wchar_t>
utf8_to_wstring_converter;
std::wstring vWCharStrFromCharStr =
utf8_to_wstring_converter.from_bytes(vCharStr);
std::wcout << "vWCharStrFromCharStr = '" << vWCharStrFromCharStr << "'"
<< std::endl;
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Msys2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/msys2-users