文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>boost::property_tree

boost::property_tree

时间:2010-12-13  来源:Old

 

property_tree 特别适合于应用程序的配置数据处理,可以解析 xml, int, 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>[email protected]</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", "[email protected]");
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 

 

 

 

相关阅读 更多 +
排行榜 更多 +
野生恐龙射击生存安卓版

野生恐龙射击生存安卓版

飞行射击 下载
战场狙击手

战场狙击手

飞行射击 下载
1v1布娃娃射击安卓版

1v1布娃娃射击安卓版

飞行射击 下载