Cross-platform INI file read/write API (C ++ Version)

Source: Internet
Author: User
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

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.