版本: 0.2.1
授权方式:GNU GPL
著作权所有(c) 2007 Midapex
本程序为自由软件;您可依据自由软件基金会所发表的GNU通用公共授权条款规定,就本程序再为发布与/或修改;无论您依据的是本授权的第二版或(您自行选择的)任一日后发行的版本。
本程序是基于使用目的而加以发布,然而不负任何担保责任;亦无对适售性或特定目的适用性所为的默示性担保。详情请参照GNU通用公共授权。
源代码下载地址: http://www.cppblog.com/Files/dyj057/IniFileCppV0.2.1.zip
描述:
应大家要求,发布C++版本,它是对C语言版本的简单封装,更方便大家使用。
C语言版本地址: http://www.cppblog.com/dyj057/archive/2007/12/07/37958.html
已测试通过的开发环境:
WinXP+VS2005
Ubuntu 7.10 + g++4.1
arm-linux-gcc3.3.4
项目特点:
1.使用标准C库函数,支持Windows、Linux、Unix等多平台。
2.实现小巧精致,长期开源支持。
使用示例代码如下:
为了得到如下的配置:
[student]
name=Tony
age=20
[teacher]
name=Tom
age=50
可以运行如下的代码:
1 #include "IniFile.h"
2 #include <iostream>
3 using namespace std;
4
5 int main()
6 {
7 cout << "Midapex IniFile API 0.2.1" << endl;
8 string name_key = "name";
9 string age_key = "age";
10
11 //using ini file path init a IniFile object
12 IniFile ini("myconfig.ini");
13
14 //set current section
15 ini.setSection("student");
16
17 if(!ini.write(name_key,"Tony"))
18 {
19 cout << "write name to ini file fail"<<endl;
20 return -1;
21 }
22
23 if(!ini.write(age_key,20))
24 {
25 cout << "write age to ini file fail"<<endl;
26 return -1;
27 }
28
29 cout << "[" << ini.getSection()<< "]" <<endl;
30 cout << name_key << "=" << ini.readStr(name_key,"") << endl;
31 cout << age_key << "=" << ini.readInt(age_key,-1) << endl;
32
33 ini.setSection("teacher");
34
35 if(!ini.write(name_key,"Tom"))
36 {
37 cout << "write name to ini file fail"<<endl;
38 return -1;
39 }
40
41 if(!ini.write(age_key,50))
42 {
43 cout << "write age to ini file fail"<<endl;
44 return -1;
45 }
46
47 cout << "[" << ini.getSection()<< "]" <<endl;
48 cout << name_key << "=" << ini.readStr(name_key,"") << endl;
49 cout << age_key << "=" << ini.readInt(age_key,-1) << endl;
50
51 return 0;
52 }
53