跨平台INI文件读写API(C++版本)

本文介绍了一个跨平台的INI文件读写API,支持Windows、Linux和Unix等多个操作系统。该API采用C++编写,是对C语言版本的封装,便于开发者使用。提供了详细的使用示例代码。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1工程:跨平台INI文件读写API(C++版本)
版本: 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 

 
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值