对不起,我之前问过一个关于同一主题的问题,但我的问题涉及那里描述的另一个方面(如何迭代提升...)。
看看下面的代码:
#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 文档中我找不到任何好的东西,只是关于浏览节点的宏,但这种方法是我真的想避免的。
所以在这里解决我的问题:一旦在 a 上获取迭代器ptree
,我如何访问节点名称、值、参数(xml 文件中的节点)?谢谢