Boost Property_Tree迭代器,如何处理它们?

2024-04-04

抱歉,我之前问过关于同一主题的问题,但我的问题涉及那里描述的另一个方面(如何迭代提升... https://stackoverflow.com/questions/4586768/how-to-iterate-a-boost-property-tree).

看一下下面的代码:

#include <iostream>
#include <string>
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/xml_parser.hpp>
#include <boost/algorithm/string/trim.hpp>
int main(int argc, char** argv) {
     using boost::property_tree::ptree;
     ptree pt;
     read_xml("try.xml", pt);
     ptree::const_iterator end = pt.end();
     for (ptree::const_iterator it = pt.begin(); it != end; it++)
           std::cout << "Here " << it->? << std::endl;
}

好吧,正如我在提到的问题中被告知的那样,可以在property_tree在 Boost 中,但我不知道它是什么类型,以及我可以使用哪些方法或属性。

好吧,我想这一定是另一个ptree或者代表要再次浏览的另一个 xml 层次结构的东西(如果我愿意的话),但是关于此的文档非常糟糕。我不知道为什么,但在 boost 文档中我找不到任何好的东西,只是关于浏览节点的宏的东西,但这种方法是我真正想避免的一种方法。

所以在这里回答我的问题:一旦获得迭代器ptree,如何访问节点名称、值、参数(xml 文件中的节点)? 谢谢


打印完整的树:

void print(boost::property_tree::ptree const& pt)
{
    using boost::property_tree::ptree;
    ptree::const_iterator end = pt.end();
    for (ptree::const_iterator it = pt.begin(); it != end; ++it) {
        std::cout << it->first << ": " << it->second.get_value<std::string>() << std::endl;
        print(it->second);
    }
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Boost Property_Tree迭代器,如何处理它们? 的相关文章

随机推荐