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

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;

}

相关推荐
代码游侠2 小时前
学习笔记——Linux内核与嵌入式开发3
开发语言·arm开发·c++·学习
踢足球09292 小时前
寒假打卡:2026-2-3
数据库
每次学一点2 小时前
【ZeroTier自研之路】planet的组成
服务器·网络·数据库
怎么没有名字注册了啊2 小时前
C++ 进制转换
开发语言·c++
金枪不摆鳍2 小时前
C++常用关键字考察
c++
策知道2 小时前
2026年北京政府工作报告产业指标深度解析
大数据·数据库·人工智能·搜索引擎·政务
Traced back3 小时前
# C# WinForms 数据库清理系统基础知识与避坑指南
开发语言·数据库·c#
茉莉玫瑰花茶3 小时前
C++ 17 详细特性解析(4)
开发语言·c++·算法
云边有个稻草人3 小时前
金仓 VS MongoDB:国产数据库凭什么成为MongoDB平替首选?
数据库·mongodb·国产数据库·金仓·kingbasees sql
欧阳x天3 小时前
STL详解(九)—— stack和queue的模拟实现
开发语言·c++