首页 > 其他 > 详细

VS中utf8转换为unicode

时间:2017-01-22 16:51:10      阅读:483      评论:0      收藏:0      [点我收藏+]

VS中utf8转换为unicode

 

C++函数

  1. char* UTF82Char(const char* szU8)
  2. {
  3.     int wcsLen = MultiByteToWideChar(CP_UTF8, NULL, szU8, (int)strlen(szU8), NULL, 0);
  4.     wchar_t* wszString = new wchar_t[wcsLen + 1];
  5.     MultiByteToWideChar(CP_UTF8, NULL, szU8, (int)strlen(szU8), wszString, wcsLen);
  6.     wszString[wcsLen] = ‘\0‘;
  7.     int len = WideCharToMultiByte(CP_ACP, 0, wszString, (int)wcslen(wszString), NULL, 0, NULL, NULL);
  8.     char* c = new char[len + 1];
  9.     WideCharToMultiByte(CP_ACP, 0, wszString, (int)wcslen(wszString), c, len, NULL, NULL);
  10.     c[len] = ‘\0‘;
  11.     delete[] wszString;
  12.     return c;
  13. }

 

 

VS调试watch窗口中显示utf-8字符串

技术分享

 

cmd窗口显示utf-8函数

 

  1. chcp 65001        utf-8
  2. chcp 936            中文

VS中utf8转换为unicode

原文:http://www.cnblogs.com/yizhichun/p/6340505.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!