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;

}

相关推荐
MonkeyKing_sunyuhua5 分钟前
ES文档序号写错的问题的修复
java·数据库·elasticsearch
饱饱要坚持可持续发展观10 分钟前
Liquibase preConditions 执行前判断详解
数据库·liquibase
wen__xvn13 分钟前
基础算法集训第01天:线性枚举
数据结构·c++·算法
代码煮茶君18 分钟前
MySQL 数据库死锁及核心机制全解析
android·数据库·mysql
Howrun77725 分钟前
C++ 线程互斥锁 lock_guard
c++·算法
咕噜企业分发小米32 分钟前
豆包大模型在药物研发中的知识检索效率如何?
java·开发语言·数据库
橘子师兄37 分钟前
C++AI大模型接入SDK—快速上手
开发语言·c++·人工智能
LaughingZhu39 分钟前
Product Hunt 每日热榜 | 2026-01-20
数据库·人工智能·经验分享·神经网络·搜索引擎·chatgpt
SJLoveIT41 分钟前
sql注入攻击的防御思路总结
数据库·sql
偷星星的贼1144 分钟前
如何为开源Python项目做贡献?
jvm·数据库·python