首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

简略的ini文件解析

2012-12-18 
简单的ini文件解析int GetKeyVal(const string strCfg, const string strKey, string& strVal){int nRet

简单的ini文件解析

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;}
?

热点排行