Как проанализировать более 2 уровней в XML с помощью boost

Я получил этот код из библиотеки наддува.
http://www.boost.org/doc/libs/1_42_0/doc/html/boost_propertytree/tutorial.html

Это XML-файл, который они имеют

<debug>
<filename>debug.log</filename>
<modules>
<module>Finance</module>
<module>Admin</module>
<module>HR</module>
</modules>
<level>2</level>
</debug>

Код для загрузки этих значений и их распечатки

#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/xml_parser.hpp>
#include <boost/foreach.hpp>
#include <string>
#include <set>
#include <exception>
#include <iostream>

struct debug_settings
{
std::string m_file;               // log filename
int m_level;                      // debug level
std::set<std::string> m_modules;  // modules where logging is enabled
void load(const std::string &filename);
void save(const std::string &filename);
};

void debug_settings::load(const std::string &filename)
{

using boost::property_tree::ptree;
ptree pt;
read_xml(filename, pt);
m_file = pt.get<std::string>("debug.filename");
m_level = pt.get("debug.level", 0);
BOOST_FOREACH(ptree::value_type &v, pt.get_child("debug.modules"))
m_modules.insert(v.second.data());

}

void debug_settings::save(const std::string &filename)
{

using boost::property_tree::ptree;
ptree pt;

pt.put("debug.filename", m_file);

pt.put("debug.level", m_level);

BOOST_FOREACH(const std::string &name, m_modules)
pt.put("debug.modules.module", name,true);

write_xml(filename, pt);
}

int main()
{
try
{
debug_settings ds;
ds.load("debug_settings.xml");
ds.save("debug_settings_out.xml");
std::cout << "Success\n";
}
catch (std::exception &e)
{
std::cout << "Error: " << e.what() << "\n";
}
return 0;
}

Но это дает мне ошибку

/usr/include/boost/property_tree/detail/ptree_implementation.hpp:769: ошибка: запрос для элемента «put_value» в «tr», который имеет неклассовый тип «bool»

Может кто-нибудь сказать мне, что мне не хватает?

1

Решение

Кажется, они заменили функцию put () … Так что, если я изменил строку

«pt.put (» debug.modules.module «, name, true);»

в

«pt.add (» debug.modules.module «, name);»

это работает отлично. Спасибо.

2

Другие решения

Других решений пока нет …