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;

}

相关推荐
Mistra丶3 分钟前
记一次 JVM+Postgresql的 “死锁” 问题排查
jvm·数据库·postgresql·死锁
qq_417695054 分钟前
内存对齐与缓存友好设计
开发语言·c++·算法
2301_816651224 分钟前
实时系统下的C++编程
开发语言·c++·算法
一然明月5 分钟前
Qt QML 锚定(Anchors)全解析
java·数据库·qt
晓纪同学5 分钟前
EffctiveC++_02第二章
java·jvm·c++
2401_831824965 分钟前
C++与Python混合编程实战
开发语言·c++·算法
※※冰馨※※11 分钟前
【QT】TortoiseGit配 SSH 克隆 Codeup
开发语言·c++·windows
2301_8166512213 分钟前
C++中的策略模式高级应用
开发语言·c++·算法
liuyao_xianhui15 分钟前
优选算法_模拟_替换所有的‘?‘_C++
开发语言·javascript·数据结构·c++·算法·链表·动态规划
分享牛23 分钟前
Operaton入门到精通23-Operaton 2.0 原生支持 JUnit 6 核心指南
数据库·junit