Writing comments to ini file with boost::property_tree::ptree

前端 未结 1 1289
日久生厌
日久生厌 2021-01-06 02:28

Is there any way to write comments in an ini file using boost::property::ptree ?

Something like that:

  void save_ini(const std::string& path)
           


        
相关标签:
1条回答
  • 2021-01-06 03:04

    boost::property_tree::ptree is used for a variety of "property tree" types (INFO, INI, XML, JSON, etc.), so it does not inherently support anything other than being a fancy container for allowing key=>value settings. Your final line (which should be):

    boost::property_tree::ini_parser::write_ini(path, pt);
    

    is the only thing that is defining what you're doing as INI instead of one of those other formats. You could easily replace that line with writing to XML, for example, and it would also work. Therefore, you can see that the property_tree::ptree cannot have things specific to a specific type of file.


    The best you could do would be to add a "comments" setting for each of your children -- something like this:

    pt.put("something.comments", "Here are the comments for the 'something' section");
    

    You can have properties for any child with any name you want...and simply ignore them when iterating through during read. So, there's no reason not to be creative like this if you wish -- it's your program!

    0 讨论(0)
提交回复
热议问题