读写ini文件:
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/ini_parser.hpp>
#include <boost/property_tree/xml_parser.hpp>
#include <iostream>
namespace pt=boost::property_tree;
//1.先测试一把写入数据
void InitWrite(){
pt::ptree ini;
ini.put("session1.name1","AAA");
ini.put("session1.name2","BBB");
ini.put("session2.ip","1992.23.322.2;232.32.24.22;12.12.12.12");
ini.put("session3.name4","12374");
pt::write_ini("test.ini",ini);
}
//再测试读出数据来
void InitRead(){
pt::ptree ini;
pt::read_ini("test.ini",ini);
std::cout<<ini.get<std::string>("session1.name1");
std::cout<<ini.get<std::string>("session2.ip");
}
写入的数据:
读出的数据: