程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C++ >> C++入門知識 >> boost::xml——基本操作以及中文亂碼解決方案

boost::xml——基本操作以及中文亂碼解決方案

編輯:C++入門知識

2.解決boost對xml中中文亂碼問題
3.實現普通字符串和寬字符串的傻瓜切換(模仿tchar.h)
4.代碼運行環境為VS2010,需要導入boost庫才能正常運行
5.VS2010運行時可能會發生錯誤。例如:cl.exe 或者 cvtres.exe 報錯。 解決辦法就是重新打開項目或者切換其它正常項目運行一下(反正我是這麼解決的)

 

 

 

 
 
     
    
 
 #include <iostream>
 #include <>
 #include <exception>
 #include <map>
 
 
 #include <boost/property_tree/ptree.hpp>
 #include <boost/property_tree/xml_parser.hpp>
 #include <boost/program_options/detail/convert.hpp>
 #include <boost/program_options/detail/utf8_codecvt_facet.hpp>
 #include <boost/.hpp>
 
       
 
  CHINESE_CHARSET 
 
   tptree boost::property_tree::wptree
  tstring std::wstring
  _USERT(x) L ## x
 
  tptree boost::property_tree::ptree
  tstring std::string
  _USERT(x) x
 
 
  LoadXML(tptree &o_pt,        
      std::locale current_locale(locale(),  
  
 
     
     
         ( std::exception &          cout <<  << typeid(e).name() <<          cout << e.what() <<                
        
  SaveXML( tptree &i_pt,        
      std::locale current_locale(locale(),      boost::property_tree::xml_parser::xml_writer_settings<wchar_t> settings(L, , L 
      boost::property_tree::xml_parser::xml_writer_settings<> settings(, ,  
 
     
         ( std::exception &          cout <<  << typeid(e).name() <<          cout << e.what() <<            
        
 
  IsExistChildNode( tptree &i_pt,       
           tptree pt =                        ; 
          
               ; 
        ( std::exception &          cout <<  << typeid(e).name() <<          cout << e.what() <<          -; 
  
      -  
   
  IsChildNodeOrAttr( tptree &     ,      ,  &     ,  &o_nChildNodeCount 
     ,  &o_nChildNodeAttributeCount) 
      o_bChildNodeOrAttribute = ; 
     o_nChildNodeCount = ; 
     o_nChildNodeAttributeCount = ; 
 
     tstring l_strChildNode; 
     tstring l_strXmlAttr(_USERT()); 
     tstring l_strAttrPath(_USERT()); 
      l_bflag = ; 
 
     
           l_bExistChildNode =          (==               ; 
          BOOST_FOREACH ( tptree::value_type &              l_strChildNode =              (l_strChildNode==l_strXmlAttr && ==                  BOOST_FOREACH ( tptree::value_type &v, i_pt.get_child(i_strNodePath+                      ++                     o_bChildNodeOrAttribute = ; 
                  l_bflag =               
                  ++                 o_bChildNodeOrAttribute = ; 
                   ( std::exception &          cout <<  << typeid(e).name() <<          cout << e.what() <<          ; 
  
        
   
 template<typename type>  GetChildNodes( tptree &i_pt,  tstring i_strNodePath, multimap<tstring, type> &       tstring l_strXmlAttr(_USERT()); 
  
     
           l_bExistChildNode =          (==               ; 
          BOOST_FOREACH ( tptree::value_type &              l_strChildNode =             l_tpChildNodeValue = v.second.get_value<type>              (!=                  o_mmapChildNodes.insert(pair<tstring, type>              
                   runtime_error(         ( std::exception &          cout <<  << typeid(e).name() <<          cout << e.what() <<          ; 
  
        
   
 template<typename type>  GetCurrentNodeAttrs( tptree &i_pt,  tstring i_strNodePath, map<tstring, type> &       tstring l_strXmlAttr(_USERT()); 
     tstring l_strAttrPath(_USERT()); 
  
     
           l_bExistChildNode =          (==               ; 
           (l_strXmlAttr==i_pt.get_child(i_strNodePath).begin()->              BOOST_FOREACH ( tptree::value_type &v, i_pt.get_child(i_strNodePath+                  l_strChildNodeAttr =                 l_tpChildNodeAttrValue = v.second.get_value<type>                 o_mapCurrentNodeAttrs.insert(pair<tstring, type>                         
               runtime_error(        ( std::exception &          cout <<  << typeid(e).name() <<          cout << e.what() <<          ; 
  
        
    
 template<typename type>  GetChildNodesAttrs( tptree &i_pt,  tstring i_strNodePath, multimap<tstring, map<tstring, type>> &         tstring l_strXmlAttr(_USERT()); 
     tstring l_strAttrPath(_USERT()); 
 
     
           l_bExistChildNode = IsExistChildNode(i_pt, i_strNodePath); 
          (==               ; 
  
         
         tstring l_strChildNode =         tstring l_strChildNodeAttrPath = i_strNodePath+_USERT()+l_strChildNode+          l_bExistChildNodeAttr = IsExistChildNode(i_pt, l_strChildNodeAttrPath); 
          (==               ; 
  
         BOOST_FOREACH ( tptree::value_type &              map<tstring, type>             l_strChildNode =             BOOST_FOREACH ( tptree::value_type &                  l_strChildNodeAttr =                 l_tpChildNodeAttrValue = subv.second.get_value<type>                 l_mapChildNodeAttrs.insert(pair<tstring, type>              o_mmapChildNodesAttrs.insert(pair<tstring, map<tstring, type>>                  ( std::exception &          cout <<  << typeid(e).name() <<          cout << e.what() <<          ; 
  
        
 
  SetCurrentNodeValue(tptree::iterator io_iter,       
          io_iter->second.put_value<tstring>                 ( std::exception &          cout <<  << typeid(e).name() <<          cout << e.what() <<          ; 
  
        
 
  SetCurrentNodeAttrValue(tptree::iterator io_iter,       
          io_iter->second.put_value<tstring>                 ( std::exception &          cout <<  << typeid(e).name() <<          cout << e.what() <<          ; 
  
        
   
  DelCurrentNode(tptree &      
                   ( std::exception &          cout <<  << typeid(e).name() <<          cout << e.what() <<          ; 
  
        
   
 tptree::size_type DelCurrentNodes(tptree &io_pt,  tstring &      
                 ( std::exception &          cout <<  << typeid(e).name() <<          cout << e.what() <<          -; 
  
      -  
 
       
      l_strFileName1(      l_strFileName2(       f = 
                
                
                               
                               
                                                             
                                                                  
                                                             
                     
                                                             
               
     
           
                          
                          
                              
                          
                          
                          
     
 
     cout << }

 

 

 

 

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved