erase and put methods in property tree lib of boost

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

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-li... Sent from the Boost - Users mailing list archive at Nabble.com.

thanks a lot for your reply. Yes, I dug deeper into the error that day and
solved the problem by removing the const
sashidhar
On Sat, Mar 23, 2013 at 11:24 AM, ajd.
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-li... Sent from the Boost - Users mailing list archive at Nabble.com. _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
participants (2)
-
ajd.
-
Sashidhar Guntury