Search code examples
c++boostboost-propertytree

Boost Property Tree with filename as key


I am trying to use filenames as the key in boost::PropertyTree

However, the '.' character in a filename such as "example.txt" causes an additional layer to be added within the property tree. The most obvious solution would be to replace '.' with another character, but there is likely a better way to do this, such as with an escape character.

In the following example, the value 10 will be put in the node 'txt', a child of 'example'. Instead, I want the value 10 to be stored in the node 'example.txt'.

ptree pt;
pt.put("example.txt", 10);

How can I use the full filename for a single node?

Thanks in advance for your help!


Solution

  • The problem was that the documentation was outdated. A path type object must be created as follows, with another character that is invalid for file paths specified as the delimiter as follows:

    pt.put(boost::property_tree::ptree::path_type("example.txt", '|'), 10);
    

    I found a path to the solution from the boost mailing list at the newsgroup gmane.comp.lib.boost.devel posted by Philippe Vaucher.