zoukankan      html  css  js  c++  java
  • sqlite3 插入中文乱码

    我的VS2015工程使用的是unicode编码,插入中文显示一堆问号,解决办法:

    unicode编码转成UTF8

    static std::wstring UniAsciiToUnicode(const std::string& str)
    {
    	// 预算-缓冲区中宽字节的长度  
    	int unicodeLen = MultiByteToWideChar(CP_ACP, 0, str.c_str(), -1, NULL, 0);
    	// 给指向缓冲区的指针变量分配内存  
    	wchar_t *pUnicode = (wchar_t*)malloc(sizeof(wchar_t)*unicodeLen);
    	// 开始向缓冲区转换字节  
    	MultiByteToWideChar(CP_ACP, 0, str.c_str(), -1, pUnicode, unicodeLen);
    	std::wstring ret_str = pUnicode;
    	free(pUnicode);
    	return ret_str;
    }
    static std::string UnicodeToUtf8(const std::wstring& wstr)
    {
    	// 预算-缓冲区中多字节的长度  
    	int ansiiLen = WideCharToMultiByte(CP_UTF8, 0, wstr.c_str(), -1, NULL, 0, NULL, NULL);
    	// 给指向缓冲区的指针变量分配内存  
    	char *pAssii = (char*)malloc(sizeof(char)*ansiiLen);
    	// 开始向缓冲区转换字节  
    	WideCharToMultiByte(CP_UTF8, 0, wstr.c_str(), -1, pAssii, ansiiLen, NULL, NULL);
    	std::string ret_str = pAssii;
    	free(pAssii);
    	return ret_str;
    }
    //ANSI转UTF8 最终转换函数
    static std::string AsciiToUtf8(const std::string& str)
    {
    	return UnicodeToUtf8(UniAsciiToUnicode(str));
    }
    

      

  • 相关阅读:
    安装wamp的方法及过程
    js原生获取className&多选一
    构造函数
    轮播图
    NaN
    ++与--运算练习
    if语句的练习
    switch语句的练习
    九九乘法表
    mac下git提交github代码
  • 原文地址:https://www.cnblogs.com/132818Creator/p/14577454.html
Copyright © 2011-2022 走看看