找回密码
 用户注册

QQ登录

只需一步,快速开始

查看: 3569|回复: 0

支持win &linux的ini读取类

[复制链接]
发表于 2014-12-4 09:11:17 | 显示全部楼层 |阅读模式
在github上搜索到一个老外写的ini类,star挺多的。
于是拿来用,发现在windows下还有少许问题,于是改造了一下,让它兼容windows和linux。
其实很简单。
代码测试
  1. #include "iniparser.h"
  2. int main(int argc, char* argv[])
  3. {
  4.         char* pIniFileName = "TcpTest.ini";
  5.         dictionary* pDictionary = NULL;
  6.         pDictionary = iniparser_load(pIniFileName);
  7.         if(NULL == pDictionary)
  8.         {
  9.                 printf_s("[CBaseCommand::ReadIniFile](%s)Read Ini fail.\n", pIniFileName);
  10.         }
  11.         else
  12.         {
  13.                 //read ini
  14.                 char* pData = iniparser_getstring(pDictionary, "PlugIn:Name", NULL);
  15.                 if(NULL != pData)
  16.                 {
  17.                         printf_s("[CBaseCommand::ReadIniFile]Name=%s.\n", pData);
  18.                 }
  19.                 else
  20.                 {
  21.                         printf_s("[CBaseCommand::ReadIniFile]Name no find.\n");
  22.                 }
  23.                 int nData = iniparser_getint(pDictionary, "PlugIn:Number", 0);
  24.                 if(0 != nData)
  25.                 {
  26.                         printf_s("[CBaseCommand::ReadIniFile]Number=%d.\n", nData);
  27.                 }
  28.                 else
  29.                 {
  30.                         printf_s("[CBaseCommand::ReadIniFile]Number no find.\n");
  31.                 }
  32.         }
  33.         iniparser_freedict(pDictionary);
  34.         getchar();
  35.         return 0;
  36. }
复制代码
修改过的源文件在这里,我比较喜欢就几个c 的文件,很好用也不用折腾。


本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?用户注册

×
您需要登录后才可以回帖 登录 | 用户注册

本版积分规则

Archiver|手机版|小黑屋|ACE Developer ( 京ICP备06055248号 )

GMT+8, 2024-5-19 10:17 , Processed in 0.015047 second(s), 6 queries , Redis On.

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表