自己写配置文件

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

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] == ‘\n‘)

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;

}

时间: 2024-08-09 13:06:11

自己写配置文件的相关文章

初识MyBatis(如何写配置文件和简单使用)

MyBatis3.x 这里简单贴一下MyBatis的介绍,具体使用方法会在代码中贴出. MyBatis的前世今生 MyBatis的前身就是iBatis,iBatis本是由Clinton Begin开发,后来捐给Apache基金会,成立了iBatis开源项目.2010年5月该项目由Apahce基金会迁移到了Google Code,并且改名为MyBatis. 尽管如此,它的包结构仍然为ibatis. www.mybatis.org/ https://github.com/mybatis MyBati

spring项目篇2----编写配置文件

我们接下来开始编写我们的权限系统,以便进一步熟悉SSM,接下来按照第一篇起一个maven项目,项目简介如下,接下来看一下配置文件 web.xml <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd" > <web-app xmlns="http:/

hibernate中写配置文件xxx.hbm.xml时那个成员变量的类型type如何写的问题

hibernate中的类型就是8种基本类型的包装类首字母变为小写,有integer,long,short,float,double,charchter,byte,boolean,当然还包括其他类型如:yes_no,true_false hibernate中的类型的作用是匹配数据库表中字段的类型和Java类中属性的类型不匹配的问题的一种解决方案,比如string完成从java.lang.String到VARCHAR的映射,所以在xxx.hbm.xml映射文件中我们写属性的类型时会写成如type="

Spring写配置文件时不提示怎么办?

想要编写xml文件时代码提示,其实只要配置了相应的xsd文件即可,xsd文件也就是xml文件的一个约束.就是决定了你xml文件中可以写哪些东西. xsd文件是xml文件的元数据文件. 以bean标签为例: 你编写<bean>标签的时候没有提示,则可以配置pring-beans-3.0.xsd这个文件到xml头信息中 1 2 3 4 5 <?xml version="1.0" encoding="UTF-8"?> <beans xmlns

第二十篇-如何写配置文件

配置文件不同的格式所用不同函数,可能可以优化 WriteData.java package com.example.aimee.logtest; import android.os.Build; import android.support.annotation.RequiresApi; import android.util.Log; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.Fil

写配置文件

<?php $data='<?php  if ( ! defined(\'BASEPATH\')) exit(\'No direct script access allowed\'); $active_group = \'default\'; $active_record = TRUE; //DB $db[\'default\'][\'hostname\'] = \'localhost\'; $db[\'default\'][\'port\']     = \'3306\'; $db[\'de

python:配置文件configparser

#-*- coding:utf8 -*- # Auth:fulimei import configparser #第一个标签 conf=configparser.ConfigParser() conf['DEFAULT']={'ServerAliveInterval': '45', 'Compression': 'yes', 'CompressionLevel': '9'} conf['DEFAULT']['ForwardX11'] = 'yes' #第二个标签 conf['bitbucket.

编写spring配置文件时,不能出现帮助信息

在写配置文件的时候如果没有提示: <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.spring

C++ 读取配置文件

#ifndef __CFG_OP_H__ #define __CFG_OP_H__ #ifdef __cplusplus extern "C" { #endif //获取配置项 int GetCfgItem(char *pFileName /*in*/, char *pKey /*in*/, char * pValue/*in out*/, int * pValueLen /*out*/); //写配置项 int WriteCfgItem(char *pFileName /*in*/,