With the help of, Boost.PropertyTreeyou can read and update the tree, then write to the file (see functions loadand save.
See How to access data in the property tree . You can definitely add a new property or update an existing one. It mentions what is there eraseon the container so that you can delete the existing value. Example from boost(link above):
ptree pt;
pt.put("a.path.to.float.value", 3.14f);
pt.put("a.path.to.float.value", 2.72f);
pt.add("a.path.to.float.value", 3.14f);
, , .
:
ini .
, ini ini_parser, :
, ini , , :
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/ini_parser.hpp>
void save(const std::string &filename)
{
using boost::property_tree::ptree;
ptree pt;
pt.put("a.value", 3.14f);
pt.put("a.value", 2.72f);
pt.add("a.bvalue", 3.14f);
write_ini( filename, pt );
}
int main()
{
std::string f( "test.ini" );
save( f );
}
test.ini:
[a]
value=2.72
bvalue=3.14
.