boost库之ptree解析xml

9 篇文章 0 订阅
// FirstTest.cpp : 定义控制台应用程序的入口点。
//ptree解析xml
#include "stdafx.h"
#include <boost/property_tree/ptree.hpp>  
#include <boost/property_tree/xml_parser.hpp>  
#include <boost/typeof/typeof.hpp>  
#include <iostream>  
using namespace boost::property_tree;  

using namespace std;  
  
void ReadConfig()  
{  
	boost::property_tree::ptree pt;  
	boost::property_tree::read_xml("del.conf", pt);  
	int filenum = pt.get<int>("root.delfile.filenum");  

	cout << "filenum: " << filenum << endl;  

	BOOST_AUTO(paths, pt.get_child("root.delfile.paths"));  
	for (BOOST_AUTO(pos, paths.begin()); pos != paths.end(); ++pos)  
	{  
		BOOST_AUTO(path, pos->second.get_child(""));    //""表示所有
		for (BOOST_AUTO(pos_paths, path.begin()); pos_paths != path.end(); ++pos_paths)  
			cout << pos_paths->second.data() << endl;  
	}  

}  
int main()  
{  
 ReadConfig();  
 system("pause");
 return 0;  
}  


<root>  
 <delfile>  
  
  <filenum> 35 </filenum>  
  
  <paths>  
   <path>   
    <pathname>/tmp/tmp0/</pathname>  
    <before_hours> 0 </before_hours> 
   </path>  
    
   <path>   
    <pathname>/tmp/tmp1/</pathname>  
    <before_hours> 1 </before_hours>  
   </path>  
    
   <path>   
    <pathname>/tmp/tmp2/</pathname>  
    <before_hours> 2 </before_hours>  
   </path>  
    
   <path>   
    <pathname>/tmp/tmp3/</pathname>  
    <before_hours> 3 </before_hours>  
   </path>  
    
   <path>   
    <pathname>/tmp/tmp4/</pathname>  
    <before_hours> 4 </before_hours>  
   </path>  
  </paths>  
  
 </delfile>  
  
  
 <backup>  
  <backuptime> 23:59 </backuptime>  
 </backup>  
  
</root>  


  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值