zoukankan      html  css  js  c++  java
  • boost-字符编码转换:使用conv

      Windows下的字符集转换可以使用WideCharToMultiByte/ MultiByteToWideChar,Linux下字符集转换可以使用iconv()函数,下面为使用boost的conv来进行字符集转换:

    #include <boost/locale/encoding.hpp>
    
    string UTF8toGBK(const string & str)
    {
        return boost::locale::conv::between(str, "GBK", "UTF-8");
    }
    
    string GBKtoUTF8(const string & str)
    {
        return boost::locale::conv::between(str, "UTF-8", "GBK");
    }
    
    wstring GBKtoUNICODE(const string & str)
    {
        return boost::locale::conv::to_utf<wchar_t>(str, "GBK");
    }
    
    string UNICODEtoGBK(wstring wstr)
    {
        return boost::locale::conv::from_utf(wstr, "GBK");
    }
    
    string UNICODEtoUTF8(const wstring& wstr)
    {
        return boost::locale::conv::from_utf(wstr, "UTF-8");
    }
    
    wstring UTF8toUNICODE(const string & str)
    {
        return boost::locale::conv::utf_to_utf<wchar_t>(str);
    }
  • 相关阅读:
    洛谷P2050 美食节
    洛谷P2150 寿司晚宴
    区间最深LCA
    三层交换机
    VLAN 及 GVRP 配置
    GVRP
    VLAN IEEE802.1Q
    以太网端口技术
    网关与路由器
    Quidway S系列交换机
  • 原文地址:https://www.cnblogs.com/milanleon/p/7442920.html
Copyright © 2011-2022 走看看