zoukankan      html  css  js  c++  java
  • 使用MultiByteToWideChar转换UTF8为GBK(UTF8在Windows的代码页是CP_UTF8)

    两个使用的函数:
    1,UTF8转化为Unicode,inline为了编译后更快运行,老用到了,返回字符串为了使用链式表达式
    inline WCHAR  *UTF8ToUnicode(const char *str) throw()
     {
      int i = MultiByteToWideChar(CP_UTF8,MB_ERR_INVALID_CHARS,str,-1,NULL,0);         
      WCHAR   *strUnicode=new   WCHAR[i];         
      MultiByteToWideChar(CP_UTF8,MB_ERR_INVALID_CHARS,str,-1,strUnicode,i);
      return strUnicode;
      delete []strUnicode;
     }
    一定要返回WCHAR 或wchar_t类型,否则有些字符就会变成“?”,Unicode(UCS-2)是2个字节宽
     
    2,Unicode转化为UTF8,inline同上意义
    inline char *UnicodeToUTF8(const WCHAR* pText) throw()
     {
      int i= WideCharToMultiByte(CP_UTF8,0,pText,-1,NULL,0,NULL,NULL); //输入缓冲区大小是宽字符数         
      char   *strUTF8   =   new   char[i];         
      WideCharToMultiByte(CP_UTF8,0,pText,-1,strUTF8,i,NULL,NULL);
      return strUTF8;
      delete []strUTF8;
     }
     
    http://xu20cn.blog.51cto.com/274020/66117
  • 相关阅读:
    ViewPager
    SpringBoot入门
    SpringMVC拦截器
    QML布局概述(Qt Quick Layouts Overview)
    Ubuntu16.04软件安装错误处理(以安装ssh-server为例)
    VirtualBox实用网络设置
    Ubuntu安装cmake 3.9
    QML学习笔记
    Qt一些方便易用的小技巧
    Qt 4.8.5 + MinGW32 + Qt creater 安装
  • 原文地址:https://www.cnblogs.com/findumars/p/6973487.html
Copyright © 2011-2022 走看看