boost::property_tree

property_tree 是一个保存了多个属性值的树形数据结构,可以用类似路径的简单方式访问任意节点的属性,而且每个节点都可以用类似STL的风格遍历子节点。

 

property_tree 特别适合于应用程序的配置数据处理,可以解析 xml, ini, json, info 四种格式的文本数据,使用它能够减轻自己开发配置管理的工作。

 

以 XML 为例:

 

 1 
 2  /* *
 3   * Build Success By VC++ 2010
 4   *
 5   * boost::property_tree
 6   *
 7   * copyright (C) 2010, liya
 8    */
 9 
10  /* * Example XML
11   *
12   *    <app>
13   *        <version>1.0.0.1</version>
14   *        <theme>blue</theme>
15   *        <about>
16   *            <url> http://www.xyz.com </url>
17   *            <email>support@xyz.com</email>
18   *            <content>coryright (C) xyz.com 2000-2010</content>
19   *        </about>
20   *    </app>
21    */
22 
23  #include  < iostream >
24  #include  < string >
25  #include  < boost / property_tree / ptree.hpp >
26  #include  < boost / property_tree / xml_parser.hpp >
27 
28  using   namespace  std;
29  using   namespace  boost::property_tree;
30 
31  void  CreateConfig( string  filename)
32  {
33      ptree pt;
34      read_xml(filename, pt);
35 
36      pt.put( " app.version " " 1.0.0.1 " );
37      pt.put( " app.theme " " blue " );
38      pt.put( " app.about.url " " http://www.xyz.com " );
39      pt.put( " app.about.email " " support@xyz.com " );
40      pt.put( " app.about.content " " coryright (C) xyz.com 2000-2010 " );
41 
42      write_xml(filename, pt);
43  }
44 
45  int  main( int  argc,  char   * argv[])
46  {
47      CreateConfig( string ( " config.xml " ));  //  config.xml 文件必须存在,但可以为空。
48 
49       return   0 ;
50  }
51 

 

 

 

转载于:https://www.cnblogs.com/bruceleeliya/archive/2010/12/13/1904458.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值