zoukankan      html  css  js  c++  java
  • boost.property_tree读取中文乱码问题

    最近突然怀念这个ID了,就找回来了,以后陆续把其他博客文章整理回来

    boost库很好用,不过有些库比较新,用起来磕磕碰碰的,比如这个boost.property_tree默认情况下对宽字符支持不怎么友好

    搜了一下,经过几次尝试,找到了好的方案,需要先做一次本地化编码转换:

    #include "boost/program_options/detail/utf8_codecvt_facet.hpp"
     
    int test()
    {
        std::wifstream f(L"测试.xml");
        std::locale utf8Locale(std::locale(),new boost::program_options::detail::utf8_codecvt_facet());
        f.imbue(utf8Locale);
         
        if(f)
        {
            boost::property_tree::read_xml(f,pt);
            std::wstring text = pt.get(L"test",L"");
            MessageBox(NULL,text.c_str(),L"",MB_OK);
        }
    }
  • 相关阅读:
    ListIterator
    List与set
    iterator取集合元素
    我眼中的AI
    集合的共性方法
    集合转数组
    打开与关闭eclipse的自动补全功能
    Mr_matcher的细节1
    nodelet的应用
    nodelet的理解
  • 原文地址:https://www.cnblogs.com/wuyaSama/p/2470284.html
Copyright © 2011-2022 走看看