[Boost-users] erase and put methods in property tree lib of boost

744 views
Skip to first unread message

Sashidhar Guntury

unread,
Mar 21, 2013, 12:45:13 PM3/21/13
to boost...@lists.boost.org
I have been trying to use the put and erase methods in boost's property tree library with very limited success. I have tried to go through the documentation but it seems really esoteric with no real example to demonstrate. This is what I would like to do -

I have a json object. I look for a particular key (call it "title") and extract the corresponding value (call it "Eric Clapton"), do something with "Eric Clapton" (say change it to "ec") insert it in the place of the old value. Now, should I do an "erase" to remove the previous entry and then "put" the new pair? Will "put" replace the old value?

    void doSomething(const ptree& node)
    {
        ...
        BOOST_FOREACH(const ptree::value_type& child, node.get_child("artists"))
        {
            string text = child.second.get<string>("title");
            // do something to the text to give text2
            child.second.put("title", text2);
        }
        ...
    }


The above code gives an error which is equally hard to understand. I was hoping someone would shed some light.

thanks
Sashidhar

ajd.

unread,
Mar 23, 2013, 11:24:58 AM3/23/13
to boost...@lists.boost.org
Remove the `const` from your types, `put` and `erase` modify the object state
and you can't invoke them using const references to ptree.



--
View this message in context: http://boost.2283326.n4.nabble.com/erase-and-put-methods-in-property-tree-lib-of-boost-tp4644405p4644442.html
Sent from the Boost - Users mailing list archive at Nabble.com.
_______________________________________________
Boost-users mailing list
Boost...@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users

Sashidhar Guntury

unread,
Mar 23, 2013, 12:41:38 PM3/23/13
to boost...@lists.boost.org
thanks a lot for your reply. Yes, I dug deeper into the error that day and solved the problem by removing the const

sashidhar
Reply all
Reply to author
Forward
0 new messages