Boost logo

Boost Users :

Subject: [Boost-users] [property tree] silly beginners question
From: Dietmar Hummel (hummel_at_[hidden])
Date: 2010-08-20 16:37:51

Hi all!

I am trying to read an xml file with property tree (first try).
Because I have dots int the tag names I must use the extended version of
the get functions.
So here is the slightly modified example code, which sadly does'nt
compile on vc2008.
Probably its a totally silly error on my side...

// Loads debug_settings structure from the specified XML file
void load(const std::string &filename)
     // Create an empty property tree object
     using boost::property_tree::ptree;
     ptree pt;

     // Load the XML file into the property tree. If reading fails
     // (cannot open file, parse error), an exception is thrown.
     read_xml(filename, pt);

     // Get the filename and store it in the m_file variable.
     // Note that we construct the path to the value by separating
     // the individual keys with dots. If dots appear in the keys,
     // a path type with a different separator can be used.
     // If the debug.filename key is not found, an exception is thrown.
     std::string m_file = pt.get< std::string >( '/', "debug/filename" );

     // Get the debug level and store it in the m_level variable.
     // This is another version of the get method: if the value is
     // not found, the default value (specified by the second
     // parameter) is returned instead. The type of the value
     // extracted is determined by the type of the second parameter,
     // so we can simply write get(...) instead of get<int>(...).
     int m_level = pt.get( '/', "debug/level", 0);

     // Iterate over the debug.modules section and store all found
     // modules in the m_modules set. The get_child() function
     // returns a reference to the child at the specified path; if
     // there is no such child, it throws. Property tree iterators
     // are models of BidirectionalIterator.

     std::vector< std::string > m_modules;
     BOOST_FOREACH( ptree::value_type &v, pt.get_child( '/',
"debug/modules" ) )
         m_modules.push_back( );

vc says:
1>c:\projekte\proptreetest\proptreetest\proptreetest.cpp(23) : error
C2664: 'std::basic_string<_Elem,_Traits,_Ax>
boost::property_tree::string_path<String,Translator> &,const Type &)
const': Konvertierung des Parameters 1 von 'char' in 'const
boost::property_tree::string_path<String,Translator> &' nicht möglich
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>,
1> _Ax=std::allocator<char>,
1> Key=std::string,
1> Data=std::string,
1> String=std::string,
1> Translator=boost::property_tree::id_translator<std::string>,
1> Type=std::string
1> ]
1> and
1> [
1> String=std::string,
1> Translator=boost::property_tree::id_translator<std::string>
1> ]

So, it looks to me like the compiler does'nt know about the extended get


Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at