1 Project: cross-platform INI file read/write API (C ++ Version)
Version: 0.2.1
Authorization method: GNU GPL
Copyright ownership (c) 2007 midapex
This procedure is free software; you may release and/or modify this procedure in accordance with the GNU General Public Authorization terms published by the Free Software Foundation; whether you are based on the second version of this authorization or any version you choose to release later.
This procedure is published for the purpose of use, but is not subject to any Warranty liability; and there is no implied guarantee for the suitability of the sale or specific purpose. For more information, see GNU General Public Authorization.
Source code: http://www.cppblog.com/Files/dyj057/IniFileCppV0.2.1.zip
Description:
C ++ is a simple encapsulation of the C language version to facilitate your use.
C language address: http://www.cppblog.com/dyj057/archive/2007/12/07/37958.html
Tested development environment:
WINXP + vs2005
Ubuntu 7.10 + G ++ 4.1
Arm-linux-gcc3.3.4
Project features:
1. Use Standard C library functions to support windows, Linux, UNIX, and other platforms.
2. Small and exquisite implementations with long-term open-source support.
The sample code is as follows:
To get the following Configuration:
[Student]
Name = Tony
Age = 20
[Teacher]
Name = Tom
Age = 50
You can run the following code:
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