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;

}

相关推荐
Raymond运维4 分钟前
MariaDB源码编译安装(二)
运维·数据库·mariadb
沢田纲吉16 分钟前
🗄️ MySQL 表操作全面指南
数据库·后端·mysql
saltymilk10 小时前
C++ 模板参数推导问题小记(模板类的模板构造函数)
c++·模板元编程
感哥11 小时前
C++ lambda 匿名函数
c++
RestCloud16 小时前
SQL Server到Hive:批处理ETL性能提升30%的实战经验
数据库·api
RestCloud16 小时前
为什么说零代码 ETL 是未来趋势?
数据库·api
沐怡旸17 小时前
【底层机制】std::unique_ptr 解决的痛点?是什么?如何实现?怎么正确使用?
c++·面试
感哥17 小时前
C++ 内存管理
c++
ClouGence18 小时前
CloudCanal + Paimon + SelectDB 从 0 到 1 构建实时湖仓
数据库
博笙困了1 天前
AcWing学习——双指针算法
c++·算法