string UTF82ASCII(const char* cont)
{
if (NULL == cont)
{
return string("");
}
int num = MultiByteToWideChar(CP_UTF8, NULL, cont, -1, NULL, NULL);
wchar_t* buffw = new wchar_t[(unsigned int)num];
MultiByteToWideChar(CP_UTF8, NULL, cont, -1, buffw, num);
int len = WideCharToMultiByte(CP_ACP, 0, buffw, num - 1, NULL, NULL, NULL, NULL);
char* lpsz = new char[(unsigned int)len + 1];
WideCharToMultiByte(CP_ACP, 0, buffw, num - 1, lpsz, len, NULL, NULL);
lpsz[len]='\0';
delete[] buffw;
string rtn(lpsz);
delete[] lpsz;
return rtn ;
}
/*********************************************************
函数名: A2UTF8
函数描述: 多字节转UTF8
输入参数: cont - 多字节字符串
输出参数:
返回值: UTF8编码的字符串
**********************************************************/
string ASCII2UTF8(const char* cont)
{
if (NULL == cont)
{
return string("");
}
int num = MultiByteToWideChar(CP_ACP, NULL, cont, -1, NULL, NULL);
wchar_t* buffw = new wchar_t[(unsigned int)num];
MultiByteToWideChar(CP_ACP, NULL, cont, -1, buffw, num);
int len = WideCharToMultiByte(CP_UTF8, 0, buffw, num - 1, NULL, NULL, NULL, NULL);
char* lpsz = new char[(unsigned int)len + 1];
WideCharToMultiByte(CP_UTF8, 0, buffw, num - 1, lpsz, len, NULL, NULL);
lpsz[len]='\0';
delete[] buffw;
string rtn(lpsz);
delete[] lpsz;
return rtn;
}
UTF8 to ASCII & ASCII to UTF8
最新推荐文章于 2023-10-12 15:03:34 发布