跨平台INI檔案讀寫API(C++版本)

來源:互聯網
上載者:User
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 

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.