解析config文件 练手代码
解析一个如下的CONFIG文件
#config.txt
#SHTTPD Web 服务器配置文件示例
#侦听端口
ListenPort = 80
#最大并发访问客户端数目
MaxClient = 8
#Web网页根目录
DocumentRoot = /home/www/
#CGI根目录
CGIRoot = /home/www/cgi-bin/
#默认访问文件名
DefaultFile = index.html
#客户端空闲链接超时时间
TimeOut = 5
代码
#include <fstream>
#include <string>
#include <map>
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cctype>
#include <locale> class GetConfigInfo {
public:
bool ReadFile(std::string fileName); private:
std::map<std::string, std::string> configMap;
std::fstream fin_;
}; bool GetConfigInfo::ReadFile(std::string fileName) {
fin_.open(fileName);
if (fin_.bad())
return false;
std::string readLine;
while (getline(fin_, readLine)) //逐行读取,直到结束
{
size_t i = readLine.find("#");
if (i != std::string::npos)
continue;
i = readLine.find_first_of(" \t");
while (i != std::string::npos)
{
readLine.erase(i,1);
i = readLine.find_first_of(" \t");
}
std::cout << readLine << std::endl;
i = readLine.find("=");
if (i == std::string::npos)
continue;
std::string s1 = readLine.substr(0,i);
std::string s2 = readLine.substr(i + 1, std::string::npos);
configMap.insert(std::pair<std::string, std::string>(s1, s2));
} fin_.close();
return true;
} int main()
{
GetConfigInfo gci;
gci.ReadFile("config.txt");
return 0;
}
解析config文件 练手代码的更多相关文章
- python网页抓取练手代码
from urllib import request import html.parser class zhuaqu(html.parser.HTMLParser): blogHtml = " ...
- JAVA使用SAX解析XML文件
在我的另一篇文章(http://www.cnblogs.com/anivia/p/5849712.html)中,通过一个例子介绍了使用DOM来解析XML文件,那么本篇文章通过相同的XML文件介绍如何使 ...
- java解析properties文件
在自动化测试过程中,经常会有一些公用的属性要配置,以便后面给脚本使用,我们可以选择xml, excel或者json格式来存贮这些数据,但其实java本身就提供了properties类来处理proper ...
- init进程解析rc文件的相关函数分析
init进程的源码文件位于system/core/init,其中解析rc文件语法的代码放在五个函数中, init_parse_config_file (init_parser.c), read_fil ...
- android 生成、pull解析xml文件
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools= ...
- 解析Markdown文件生成React组件文档
前言 最近做的项目使用了微前端框架single-spa. 对于这类微前端框架而言,通常有个utility应用,也就是公共应用,里面是各个子应用之间可以共用的一些公共组件或者方法. 对于一个团队而言,项 ...
- webpack练手项目之easySlide(二):代码分割(转)
在上一篇 webpack练手项目之easySlide(一):初探webpack 中我们一起为大家介绍了webpack的基本用法,使用webpack对前端代码进行模块化打包. 但是乍一看webpack ...
- webpack练手项目之easySlide(二):代码分割
Hello,大家好. 在上一篇 webpack练手项目之easySlide(一):初探webpack 中我们一起为大家介绍了webpack的基本用法,使用webpack对前端代码进行模块化打包. 但 ...
- JAVA解析XML文件(DOM,SAX,JDOM,DOM4j附代码实现)
1.解析XML主要有四种方式 1.DOM方式解析XML(与平台无关,JAVA提供,一次性加载XML文件内容,形成树结构,不适用于大文件) 2.SAX方式解析XML(基于事件驱动,逐条解析,适用于只处理 ...
随机推荐
- Android 开发有哪些新技术出现?
这里记录一下在知乎回答的<Android 开发有哪些新技术出现?>.知乎链接在这里. 原问题如下: Android 开发有哪些新技术出现?可以从UI设计或者一些核心的算法之类的说起 这是我 ...
- sysfs中属性文件的建立
1.device中建立属性文件 (1)函数调用关系: /**************************************************************/ device_c ...
- Yocto使用小技巧
1. 借助Yocto编译模块 SRC := mytest obj-m := $(SRC).o KDIR := /media/Yocto/build/tmp/work/poky-linux/linux- ...
- bzoj2750最短路计数
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2750 枚举每一个起点,通过该边的子树中有多少节点就知道本次它被经过几次了: 因为同一起点到该 ...
- web常用测试点记录
输入框 1.字符型输入框: 单行文本输入框:英文全角.英文半角.数字.空或者空格.特殊字符“~!@#¥%……&*?[]{}”,特别要注意单引号和&符号.如果禁止直接输入特殊字符时,使用 ...
- Eclipse中配置Maven build打包
Eclipse中配置Maven build打包 clean package
- mysql-1安装和数据库的管理
1.安装 直接docker安装,客户端使用Navicat Premium. docker run -d --name csjmysql -p 3306:3306 -e MYSQL_ROOT_PASSW ...
- 简单的自动化测试模型(python+selenium)
刚接触自动化测试,由于没有编程语言的基础,是搞不懂代码里面的函数.封装.包以及其他概念,只是了解字符串.数组.元组及字典这种最基本的名词,更不懂自动化测试框架了. ...
- email 解析 ,发送 邮件
email 来源:https://blog.csdn.net/xyang81/article/details/7675160 详见此人其它mail 篇 参考2:http://lib.csdn. ...
- jeesite快速开发平台(四)----数据库各表一览
转自:https://blog.csdn.net/u011781521/article/details/55194309