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 }
View Code

相关文章:

  • 2021-09-09
  • 2022-12-23
  • 2021-12-29
  • 2021-06-30
  • 2021-08-27
  • 2021-10-12
  • 2022-02-06
  • 2021-07-24
猜你喜欢
  • 2021-08-09
  • 2021-07-31
  • 2022-01-25
  • 2021-11-13
  • 2021-10-24
  • 2022-12-23
相关资源
相似解决方案