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;

}

相关推荐
A***F157几秒前
Redis开启远程访问
数据库·redis·缓存
v***4467几秒前
【MySQL — 数据库基础】深入理解数据库服务与数据库关系、MySQL连接创建、客户端工具及架构解析
数据库·mysql·架构
v***59835 分钟前
Django视图与URLs路由详解
数据库·django·sqlite
阿巴~阿巴~13 分钟前
JsonCpp:C++ JSON处理利器
linux·网络·c++·json·tcp·序列化和反序列化
i***486119 分钟前
MySQL中的GROUP_CONCAT()函数详解与实战应用
数据库·mysql
K***430622 分钟前
MySQL中的TRUNCATE TABLE命令
数据库·mysql
tyatyatya26 分钟前
MATLAB图形标注教程:title()/xlabel()/ylabel()/legend()/grid on全解析
数据库·matlab·信息可视化
e***956429 分钟前
DBeaver连接本地MySQL、创建数据库表的基础操作
数据库·mysql
左灯右行的爱情33 分钟前
MySQL高并发-主从架构
数据库·mysql·架构
zhglhy36 分钟前
DBeaver数据库管理工具介绍
数据库·dbeaver