BOOST_FOREACH(boost::property_tree::ptree::value_type &v, config.get_child("path.to.array_of_objects")) { std::cout << "First data: " << v.first.data() << std::endl; boost::property_tree::ptree subtree = (boost::property_tree::ptree) v.second ; BOOST_FOREACH(boost::...
autochild = ptree.get_child(path); child.clear(); Run Code Online (Sandbox Code Playgroud) 实际上并没有删除子项,而只是删除了它的内容。 成员erase函数采用迭代器或键。我不知道有一种简单的方法可以找到与路径相对应的迭代器,而无需遍历树。 通过在点字符处分割路径,然后对erase剩余的进行 ing,可以...
pt::ptree tree;stringm_file ="./ss.xml";try{//pt::read_xml(m_file, tree);//读取,去掉空格pt::read_xml(m_file, tree, boost::property_tree::xml_parser::trim_whitespace, std::locale());//1std::stringstrName = tree.get<std::string>("localinfo.PopupMessages.MSGID_NOUPDATE"); co...
#include<boost/property_tree/ptree.hpp>#include<boost/optional.hpp>#include<iostream>#include<cstdlib>structstring_to_int_translator{typedefstd::string internal_type;typedefintexternal_type;boost::optional<int>get_value(conststd::string &s){char*c;longl = std::strtol(s.c_str(), &c,);retu...
22 using boost::property_tree::ptree; 23 ptree pt; 24 25 read_xml(filename, pt); 26 itsTotalNumber = pt.get<int>("debug.total"); 27 28 BOOST_FOREACH(ptree::value_type &v, pt.get_child("debug.persons")) 29 { 30 //m_modules.insert(v.second.data()); ...
read_xml(m_iworldDir.string(), pt, boost::property_tree::xml_parser::trim_whitespace); } catch (conststd::exception& e) {cout<<"read error"<< e.what() <<endl; } ptree &ptchild = pt.get_child("World.Levels.Level.Root.Entity.RootArea.Root.Entity.Entities");//遍历所有itemsfor(...
一般可以用 read_xxx(filename, ptree) 将文件读入 boost::property_tree::ptree 中,之后我们可以用 get 模板方法(可带缺省值)获得某个 node 里面的值(并转换类型),对应使用的是到该 node 的 tag path,中间用点进行分隔。如果是数组类型的,可以用 get_child 方法返回一个类型为 ptree::value_type 的...
get_child("users"); for (const auto& user : users) { const boost::property_tree::ptree& user_info = user.second; std::string name = user_info.get<std::string>("name"); int age = user_info.get<int>("age"); std::string email = user_info.get<std...
auto& subtree = pt.get_child("category"); subtree = nodup(subtree, [](ptree::value_typeconst& item) {returnitem.second.get("<xmlattr>.type",""); }); write_xml(std::cout, pt, boost::property_tree::xml_writer_make_settings<std::string>(' ',4,"utf-8")); ...
ptree pt; read_xml("conf.xml",pt); //读入一个xml文件 cout<<"ID is "<<pt.get<int>("con.id")<<endl; //读取节点中的信息 cout<<"Try Default"<<pt.get<int>("con.no_prop",100)<<endl; //如果取不到,则使用默认值 ptree child = pt.get_child("con"); //取一个子节点 ...