boost.property_tree

2015-07-20 17:38:09 · 作者: · 浏览: 5
//made by davidsu33
//boost.property_tree是一个保存了多个属性值的树形数据结构
//boost.property_tree可以解析xml ini json和info四种格式的文本

#include 
  
   
#include 
   
     #include 
    
      #include 
     
       #include 
      
        #include 
       
         using namespace std; void putline(const char * str) { cout<
        
         ("conf.theme"); int guiID = pt.get
         
          ("conf.gui"); //int id = pt.get_value
          
           (); assert(guiID == 1); //不存在属性返回默认值 int def = pt.get
           
            ("conf.no", 100000); assert(def = 100000); BOOST_AUTO(childs2, pt.get_child("conf.urls")); PTree childs = pt.get_child("conf.urls"); //??? //int count = pt.count("urls"); //assert(count == 3); //读取多子节点的数据 BOOST_AUTO(it, childs.begin()); BOOST_AUTO(iend, childs.end()); for (; it != iend; ++it) { //迭代器指向ptree的value_type, //它的second成员是子节点自身 //cout<
            
             second.get_value
             
              ()<
              
               second.data()<
               
(""); //读取XML声明 BOOST_ASSERT(pt.get ("conf.gui. .lib") == "QT"); BOOST_ASSERT(pt.get ("conf.theme. .id") == 1002); BOOST_ASSERT(pt.get ("conf. ") == "this is conf comment"); //貌似不支持CDATA,测试未通过 //std::string xmltext = pt.get ("conf. "); //BOOST_ASSERT(pt.get ("conf. ") == "字符数据-character data"); } int _tmain(int argc, _TCHAR* argv[]) { parse_xml(); getchar(); return 0; }