以下代码正常工作:
#include <iostream>
#include <boost/property_tree/ptree.hpp>
#include <string>
using namespace boost::property_tree;
int main()
{
ptree root;
root.put("building.age", "42");
root.put("company.age", "32");
root.put("street.age", "19");
ptree attached_node;
attached_node.put("confirmed","yes");
attached_node.put("approved","yes");
for(auto it=root.begin();it!=root.end();++it)
{
std::cout
<< (it->first)
<< ": "
<< (it->second.get<std::string>("age"))
<< std::endl;
if(it->first=="company")
root.insert(it,make_pair("conditions",attached_node));
}
return 0;
}
但是,一旦我通过以下方式反向迭代:
for(auto it=root.rbegin();it!=root.rend();++it)
我面临一个错误:
error: no matching function for call to ‘boost::property_tree::basic_ptree<std::__cxx11::basic_string<char>, std::__cxx11::basic_string<char> >::insert(boost::property_tree::basic_ptree<std::__cxx11::basic_string<char>, std::__cxx11::basic_string<char> >::reverse_iterator&, std::pair<const char*, boost::property_tree::basic_ptree<std::__cxx11::basic_string<char>, std::__cxx11::basic_string<char> > >)’
root.insert(it,make_pair("conditions",attached_node));
^
我该如何解决这个问题?