Sqlite c++操作数据库中文乱码

2024-01-01 11:48:31

char* Utf2Gb(const char* utf8)
{
?? ?int len = MultiByteToWideChar(CP_UTF8, 0, utf8, -1, NULL, 0);
?? ?wchar_t* wstr = new wchar_t[len + 1];
?? ?memset(wstr, 0, len + 1);
?? ?MultiByteToWideChar(CP_UTF8, 0, utf8, -1, wstr, len);
?? ?len = WideCharToMultiByte(CP_ACP, 0, wstr, -1, NULL, 0, NULL, NULL);
?? ?char* str = new char[len + 1];
?? ?memset(str, 0, len + 1);
?? ?WideCharToMultiByte(CP_ACP, 0, wstr, -1, str, len, NULL, NULL);
?? ?if (wstr) delete[] wstr;
?? ?return str;
}
//GB2312到UTF-8的转换
char* GB2Utf(const char* gb2312)
{
?? ?int len = MultiByteToWideChar(CP_ACP, 0, gb2312, -1, NULL, 0);
?? ?wchar_t* wstr = new wchar_t[len + 1];
?? ?memset(wstr, 0, len + 1);
?? ?MultiByteToWideChar(CP_ACP, 0, gb2312, -1, wstr, len);
?? ?len = WideCharToMultiByte(CP_UTF8, 0, wstr, -1, NULL, 0, NULL, NULL);
?? ?char* str = new char[len + 1];
?? ?memset(str, 0, len + 1);
?? ?WideCharToMultiByte(CP_UTF8, 0, wstr, -1, str, len, NULL, NULL);
?? ?if (wstr) delete[] wstr;
?? ?return str;
}

文章来源:https://blog.csdn.net/woshidaniu/article/details/135323099
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。