Skip to content

Instantly share code, notes, and snippets.

@benjaminalt
Created April 13, 2018 07:19
Show Gist options
  • Select an option

  • Save benjaminalt/af3e2a4b3dc5ecef34bf2a40b7bfa01f to your computer and use it in GitHub Desktop.

Select an option

Save benjaminalt/af3e2a4b3dc5ecef34bf2a40b7bfa01f to your computer and use it in GitHub Desktop.
Print a boost::property_tree
std::string indent(int level)
{
std::string s;
for (int i = 0; i<level; i++) s += " ";
return s;
}
void printTree(boost::property_tree::ptree &pt, int level)
{
if (pt.empty())
{
std::cout << "\"" << pt.data() << "\"";
}
else
{
if (level) std::cout << std::endl;
std::cout << indent(level) << "{" << std::endl;
for (boost::property_tree::ptree::iterator pos = pt.begin(); pos != pt.end();)
{
std::cout << indent(level + 1) << "\"" << pos->first << "\": ";
printTree(pos->second, level + 1);
++pos;
if (pos != pt.end())
{
std::cout << ",";
}
std::cout << std::endl;
}
std::cout << indent(level) << " }";
}
std::cout << std::endl;
return;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment