weixin_42342710
weixin_42342710
采纳率0%
2018-12-27 15:01 阅读 2.5k

C程序编码转换GBK转UTF-8

我想问一下,我c程序编码是gbk的,但是我接收的信息是utf-8的,我要把这串信息丢到数据库里,数据库也是utf-8的,我怎么样把我的程序编码转换成utf-8呢

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

2条回答 默认 最新

  • haisan000 haisan000 2018-12-27 07:16
    std::string AnsiToUTF8(const char *szAnsi)
    {
                WCHAR*     strA;
                int   i = MultiByteToWideChar(CP_ACP, 0, szAnsi, -1, NULL, 0);
                strA = new  WCHAR[i];
                MultiByteToWideChar(CP_ACP, 0, szAnsi, -1, strA, i);
    
                i = WideCharToMultiByte(CP_UTF8, 0, strA, -1, NULL, 0, NULL, NULL);
                char *strB = new char[i];
                WideCharToMultiByte(CP_UTF8, 0, strA, -1, strB, i, NULL, NULL);
    
                string utf8(strB, i - 1);
    
                delete[]strA;
                delete[]strB;
    
                return utf8;
    }
    
    点赞 评论 复制链接分享
  • weixin_43231223 weixin_43231223 2018-12-27 08:49

    用setParameters

    点赞 评论 复制链接分享

相关推荐