版本: 0.2.1
授權方式:GNU GPL
著作權所有(c) 2007 Midapex
本程序為自由軟件;您可依據自由軟件基金會所發表的GNU通用公共授權條款規定,就本程序再為發布與/或修改;無論您依據的是本授權的第二版或(您自行選擇的)任一日后發行的版本。
本程序是基于使用目的而加以發布,然而不負任何擔保責任;亦無對適售性或特定目的適用性所為的默示性擔保。詳情請參照GNU通用公共授權。
源代碼下載地址:http://www.shnenglu.com/Files/dyj057/IniFileCppV0.2.1.zip
描述:
應大家要求,發布C++版本,它是對C語言版本的簡單封裝,更方便大家使用。
C語言版本地址:http://www.shnenglu.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