C++ UTF8和GB2312相互转换

#include <Windows.h>
#include <string>
using std::string; void UTF8_to_GB2312(const char* utf8, string& gb2312_str)
{
int len = MultiByteToWideChar(CP_UTF8, , utf8, -, NULL, );
wchar_t* wstr = new wchar_t[len+];
memset(wstr, , len+);
MultiByteToWideChar(CP_UTF8, , utf8, -, wstr, len);
len = WideCharToMultiByte(CP_ACP, , wstr, -, NULL, , NULL, NULL);
char* str = new char[len+];
memset(str, , len+);
WideCharToMultiByte(CP_ACP, , wstr, -, str, len, NULL, NULL);
delete[] wstr;
gb2312_str = str;
delete[] str;
return;
} void GB2312_to_UTF8(const char* gb2312, string& utf8_str)
{
int len = MultiByteToWideChar(CP_ACP, , gb2312, -, NULL, );
wchar_t* wstr = new wchar_t[len+];
memset(wstr, , len+);
MultiByteToWideChar(CP_ACP, , gb2312, -, wstr, len);
len = WideCharToMultiByte(CP_UTF8, , wstr, -, NULL, , NULL, NULL);
char* str = new char[len+];
memset(str, , len+);
WideCharToMultiByte(CP_UTF8, , wstr, -, str, len, NULL, NULL);
delete[] wstr;
utf8_str = str;
delete[] str;
return;
}
上一篇:centos7.1-64bit安装qtcreator


下一篇:LeetCode题解33.Search in Rotated Sorted Array