Boost: property_tree

Source: Internet
Author: User

Boost: property_tree-Old-blog

Boost: property_tree

Property_tree is a tree data structure that stores multiple attribute values. You can access attributes of any node in a simple way like a path, and each node can traverse subnodes in a similar STL style.

 

Property_treeEspecially suitable for application configuration data processingYou can parse text data in four formats: xml, ini, json, and info, which can ease your development and configuration management.

 

Take XML as an example:

 

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 * http://www.xyz.com
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"); // the config. xml file must exist, but can be empty.
48
49 return 0;
50}
51

Property_tree is a tree data structure that stores multiple attribute values. You can access attributes of any node in a simple way like a path, and each node can traverse subnodes in a similar STL style.

 

Property_treeEspecially suitable for application configuration data processingYou can parse text data in four formats: xml, ini, json, and info, which can ease your development and configuration management.

 

Take XML as an example:

 

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 * http://www.xyz.com
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"); // the config. xml file must exist, but can be empty.
48
49 return 0;
50}
51

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.