vico
vico

Reputation: 18171

Write ini file values without overwriting whole ini with boost

I have function that writes one section of ini file:

boolean saveSSVar()
{
    using boost::property_tree::ptree;


    ptree pt;
    pt.put(SRV_ID, ID);
    pt.put(SRV_LOG_LEVEL, LogLevel);



    write_ini( INI_FILE_NAME, pt );

    return true;
}

Problem is that it overwrites whole file instead one section. How to solve this problem?

Upvotes: 2

Views: 859

Answers (2)

ashish singh
ashish singh

Reputation: 53

Simplest way is to keep ptree as global or static.

Upvotes: 0

sehe
sehe

Reputation: 393174

Just

  1. read in original INI
  2. update values in ptree
  3. write resultant tree to INI

Note that not all information will roundtrip 100% (see the documentation for limitations)

See also: c++ boost library - writing to ini file without overwriting?

Upvotes: 1

Related Questions