Visual Studio C++ 2015 std::codecvt with char16_t or char32_t

前端 未结 4 1275
闹比i
闹比i 2020-12-09 07:49

This code compiled OK under VS2013:

std::string Unicode::utf16_to_utf8(std::u16string utf16_string)
{
    std::wstring_convert

        
4条回答
  •  再見小時候
    2020-12-09 08:45

    Another possible workaround is to use default second template parameter (wchar_t) for wstring_convert. It is working for "MS Visual Studio 2015 update 3". Please note that it is not platform-independent solution. Windows only.

    std::string utf16_to_utf8(std::u16string u16_string)
    {
        std::wstring wide_string(u16_string.begin(), u16_string.end());
        std::wstring_convert> convert;
        return convert.to_bytes(wide_string);
    }
    

提交回复
热议问题