std::wstring UTF8ToUnicode(const std::string& utf8string)
1 { 2 int widesize = ::MultiByteToWideChar(CP_UTF8, 0, utf8string.c_str(), -1, NULL, 0); 3 if (widesize == ERROR_NO_UNICODE_TRANSLATION) 4 { 5 throw std::exception("Invalid UTF-8 sequence."); 6 } 7 if (widesize == 0) 8 { 9 throw std::exception("Error in conversion."); 10 } 11 std::vector<wchar_t> resultstring(widesize); 12 int convresult = ::MultiByteToWideChar(CP_UTF8, 0, utf8string.c_str(), -1, &resultstring[0], widesize); 13 if (convresult != widesize) 14 { 15 throw std::exception("La falla!"); 16 } 17 return std::wstring(&resultstring[0]); 18 }