提升PropertyTree:检查子代是否存在 [英] Boost PropertyTree: check if child exists
本文介绍了提升PropertyTree:检查子代是否存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试编写XML解析器,将XML文件解析为 boost :: property_tree
并遇到此问题。我该如何(迅速)检查是否存在某个财产的孩子?
I'm trying to write an XML parser, parsing the XML file to a boost::property_tree
and came upon this problem. How can I check (quickly) if a child of a certain property exists?
很明显,我可以使用 BOOST_FOREACH $ c遍历所有孩子$ c>-但是,有没有更好的解决方案?
Obviously I could iterate over all children using BOOST_FOREACH
- however, isn't there a better solution to this?
推荐答案
optional< const ptree& > child = node.get_child_optional( "possibly_missing_node" );
if( !child )
{
// child node is missing
}
这篇关于提升PropertyTree:检查子代是否存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文