/*****************************
字符转换 ANSI 转UTF-8
*****************************/
long ANSItoUTF8(CString bufRecv,char* utf8_buf)
{
long unicodeLen = ::MultiByteToWideChar(CP_UTF8, 0, bufRecv, -1, NULL, 0);
wchar_t *pUnicode = new wchar_t[unicodeLen+1];
memset(pUnicode, 0, unicodeLen * sizeof(wchar_t));
::MultiByteToWideChar(CP_UTF8, 0, bufRecv, -1, (LPWSTR)pUnicode, unicodeLen);
wstring rt_utf8 = pUnicode;
delete pUnicode;
long utf8length = rt_utf8.length();
CString str(rt_utf8.c_str());
memset(utf8_buf,0,sizeof(utf8_buf));
strcat(utf8_buf, (LPSTR)(LPCTSTR)(str));
return rt_utf8.length();
}
字符转换 ANSI 转UTF-8
最新推荐文章于 2025-11-07 22:18:00 发布
本文详细介绍了如何使用C++从ANSI编码转换为UTF-8编码的方法。通过具体的代码示例,深入解析了字符编码转换过程中的关键步骤,包括使用MultiByteToWideChar函数将ANSI字符串转换为宽字符,再将其转换为UTF-8字符串。
1万+

被折叠的 条评论
为什么被折叠?



