zoukankan      html  css  js  c++  java
  • 自己写配置文件

    记录一个载入配置文件的代码段,以保存以后使用

    bool Consumer::loadConfigFile()

    {
    if( ConfigMap.size() != 0 )
    ConfigMap.clear();
    char szFilePath[256]={0};  
    GetModuleFileNameA(NULL, szFilePath, 255);  
    (strrchr(szFilePath, '\'))[0] = 0; // 删除文件名称,仅仅获得路径字串 
    std::string path = szFilePath;
    path+= "\config.bat";




    FILE* fp = fopen( path.c_str(), "r");
    if(fp == NULL)
    {
    char buf[128];
    sprintf_s(buf,"%s open failed ",path);
    ExtLogger.Out( buf );
    return false;
    }
    char buff[50];
    while(fgets(buff, 50, fp))
    {
    for(int i=0; i< strlen(buff); i++)
    {
    if(buff[i] == ' ')
    buff[i] = 0;
    }
    std::string strSymbol = buff;
    int pos = strSymbol.find('=',0);
    ConfigMap[strSymbol.substr(0,pos)] = strSymbol.substr(pos+1, strSymbol.length()-pos-1);
    }
    if( ConfigMap.size() == 0 )
    {
    ExtLogger.Out( "ConfigFile %s can not read any data.", path.c_str() ); 
    return false;
    }
    ExtLogger.Out( "configuration file is Loaded successfully!" );
    fclose(fp);
    return true;
    }
  • 相关阅读:
    XML 的学习笔记3
    XML 的学习笔记2
    XML 的学习笔记1
    Tomcat 学习笔记2
    Tomcat 学习笔记1
    sol
    sol
    0、安装Ionic2
    ionic2 目录
    6、Angular Route 路由
  • 原文地址:https://www.cnblogs.com/bhlsheji/p/5205197.html
Copyright © 2011-2022 走看看