andylin02 发表于 2013-1-19 04:12:54

简单的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 = {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)      {            strVal = vtSec;            nRet = em_succ;            break;      }    }            if (NULL != fp)    {      fclose(fp);      fp = NULL;    }      return nRet;}
页: [1]
查看完整版本: 简单的ini文件解析