一个ini配置文件解析器

来源:互联网 发布:湖州公务员网络学堂 编辑:程序博客网 时间:2024/06/05 19:56
test.ini:
#begin[system]#参数1param1=12  ;参数2param2=12,13,14,15#支持多行模式param3=12, 13,14 ,15,18,19,20#参数4param4 = chen: hui:zong:hao:haoparam5=trueparam6 =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.csdn.net/detail/chen802311/9706881
0 0
原创粉丝点击