boost xml

来源:互联网 发布:啊哈算法属于什么 编辑:程序博客网 时间:2024/06/15 12:52
#include <iostream>#include <boost/property_tree/ptree.hpp>#include <boost/property_tree/xml_parser.hpp>#include <boost/typeof/typeof.hpp>using namespace std;using namespace boost::property_tree;int  main()    {       ptree pt;    ptree& temp = pt.add("con.object","");    temp.add("name","people");    temp.add("pos","norm");    temp.add("bndbox.xmin",11);    temp.add("bndbox.ymin",34);    temp.add("bndbox.xmax",110);    temp.add("bndbox.ymax",120);    ptree& temp1 = pt.add("con.object","");    temp1.add("name","dog");    temp1.add("pos","norm");    temp1.add("bndbox.xmin",123);    temp1.add("bndbox.ymin",23);    temp1.add("bndbox.xmax",1234);    temp1.add("bndbox.ymax",4343);    write_xml("conf.xml",pt);    read_xml("conf.xml", pt);    ptree child = pt.get_child("con");    for(BOOST_AUTO(pos,child.begin()); pos != child.end(); ++pos){      cout << pos->first.data() << endl;      if(pos->first.data() == string("object")){         ptree temp = pos->second;         cout << temp.get<string>("name")<<endl;      }    }    return 1; }
<con>    <object>        <name>people</name>         <pos>norm</pos>         <bndbox>             <xmin>11</xmin>             <ymin>34</ymin>             <xmax>110</xmax>             <ymax>120</ymax>         </bndbox>    </object>     <object>         <name>dog</name>         <pos>norm</pos>         <bndbox>             <xmin>123</xmin>             <ymin>23</ymin>             <xmax>1234</xmax>             <ymax>4343</ymax>         </bndbox>     </object> </con>

运行结果
这里写图片描述

0 0
原创粉丝点击