六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 79|回复: 0

简单的ini文件解析

[复制链接]

升级  68.2%

265

主题

265

主题

265

主题

进士

Rank: 4

积分
841
 楼主| 发表于 2013-1-19 04:12:54 | 显示全部楼层 |阅读模式
int GetKeyVal(const string strCfg, const string strKey, string& strVal){    int nRet = em_succ;    if (strKey.length() <= 0)    {        return em_err_param;    }        FILE* fp = fopen(strCfg.c_str(), "rt");            if (NULL == fp)    {        return em_err_open_file;    }        char szReadLine[ROLE_DEF_MAX_LINE_LEN] = {0};        memset(szReadLine, 0, ROLE_DEF_MAX_LINE_LEN);    nRet = em_err_no_result;            while (EOF != (fscanf(fp, "%[^\n]", szReadLine)))    {        fgetc(fp);//read '\n'        string strLine = szReadLine;        memset(szReadLine, 0, sizeof(szReadLine));                vector<string> vtSec = SplitString(strLine, "=");        if ((vtSec.size() <= 1) || (vtSec.size() > 2))        {            continue;        }        else if (strKey == vtSec[0])        {            strVal = vtSec[1];            nRet = em_succ;            break;        }    }            if (NULL != fp)    {        fclose(fp);        fp = NULL;    }        return nRet;}
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

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