解析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(基于事件驱动,逐条解析,适用于只处理 ...
随机推荐
- centos6.5下tomcat安装
1.安装JDK 安装:rpm –ivh jdk-7u5-linux-i586.rpm2.配置Tomcat 解压:tar -zxvf apache-tomcat-8.0.11.tar.gz 移动到/us ...
- CentOS6.6 VSFTP服务器安装设置
1:安装vsftpd yum install vsftpd 2:关闭防火墙 service iptables stop 3:允许21端口通行 vi /etc/sysconfig/iptables ...
- LDAP基本概念
LDAP(Lightweight Directory Access Protocol)是一种基于计算模型的客户机/服务器X.500目录服务访问协议.LDAP是从X.500目录访问协议的基础上发展过来的 ...
- nginix.conf 中的gzip模块设置
gizp模块配置 gzip on; gzip_min_length 1k; gzip_buffers 4 16k; gzip_http_version 1.0; g ...
- .net 提取注释生成API文档 帮助文档
提取注释生成API文档 一.前言 在多人协作的项目中,除了良好的代码规范外,完整的API文档也相当重要.通过文档我们快速了解系统各模块的实际接口,及其使用场景.使用示例,一定程度上降低沟通成本,和 ...
- HDU 4762 Cut the Cake(高精度)
Cut the Cake Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tota ...
- HDU 3179 二叉搜索树(树的建立)
二叉搜索树 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submi ...
- 使用Spring发送Email
配置Spring发送邮件 Spring发送邮件底层还是使用JavaMail,我在http://www.cnblogs.com/lz2017/p/6882925.html 中记录过关于JavaMail的 ...
- Input设置只读属性
input设置为只读一般用于查看详情: 格式为: (1)单纯的input框 <div class="form-group"> <label for="c ...
- vue组件化开发实践
前言 公司目前制作一个H5活动,特别是有一定统一结构的活动,都要码一个重复的轮子.后来接到一个基于模板的活动设计系统的需求,便有了一下的内容.首先会对使用Vue进行开发的一些前期需要的技术储备进行简单 ...