gpt4 book ai didi

c++ - 提升属性树

转载 作者:搜寻专家 更新时间:2023-10-31 01:18:16 25 4
gpt4 key购买 nike

基于此处的 boost 文档:

http://www.boost.org/doc/libs/1_41_0/doc/html/boost_propertytree/container.html

“一个节点中可能有多个具有相同键值的 child 。但是,这些 child 不一定是顺序的。find返回的迭代器可能会引用其中的任何一个,并且不能保证相对位置其他同名的 child 。”

示例 XML:

<library>
<book><title>Title_1</title></book>
<book><title>Title_2</title></book>
<book><title>Title_3</title></book>
</library>

示例提升代码:

ptree pt;
pt.push_back(ptree::value_type("book", ptree("title")))

// This finds the first book and cannot iterate to the second one:
ptree::const_iterator it = pt.find("book");

知道了这一点,您将如何获得所有书籍并确保您全部阅读?

最佳答案

您必须使用 equal_range 函数:

std::pair < ptree::const_assoc_iterator, ptree::const_assoc_iterator> bounds = 
pt.equal_range("book");

for (ptree::const_assoc_iterator it = bounds.first; it != bounds.second ; ++it)
{
// process *it
}

关于c++ - 提升属性树,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7327032/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com