test.ini:
#begin
[system]
#参数1
param1=12
;参数2
param2=12,13,14,15
#支持多行模式
param3=12, 13,14 ,15
,18,19,20
#参数4
param4 = chen: hui:zong:
hao:hao
param5=true
param6 =true,false,aaa,bbbb, true
[option]
demo:
#include "IniFile.h"
#include <vector>
using namespace std;
int main()
{
IniFile ini("./test.ini");
IniFile::section& sec = ini.GetSection("system");
// 一般的读取接口
int pm1 = sec["param1"].GetAsInt(0);
vector<int> pm2 = sec["param2"].GetAsIntArray("-1,-1", ',');
vector<int> pm3 = sec["param3"].GetAsIntArray("-1,-1", ',');
vector<string> pm4 = sec["param4"].GetAsStringArray("aa,bb", ':');
bool pm5 = sec["param5"].GetAsBool(false);
vector<bool> pm6 = sec["param6"].GetAsBoolArray("false, true", ',');
vector<bool> pm7 = sec["param7"].GetAsBoolArray("false, true", ',');
// 写接口
sec["param1"] = "99";
sec["param7"] = "yes, no";
IniFile::section s("extend");
s["one"] = "12";
s["two"] = "chen:13";
ini.PushSection(s);
pm1 = sec["param1"].GetAsInt(0);
pm7 = sec["param7"].GetAsBoolArray("false, true", ',');
IniFile::section& ss = ini.GetSection("extend");
vector<string> two = ss["two"].GetAsStringArray("12:13", ':');
ini.Flush("./test_new.ini");
return 0;
}
download url: http://download.youkuaiyun.com/detail/chen802311/9706881