C++ 中使用boost::property_tree读取解析ini文件
boost 官网 http://www.boost.org/
下载页面 http://sourceforge.net/projects/boost/files/boost/1.53.0/
我下载的是 boost_1_53_0.tar.gz
使用系统 ubuntu 12.10
一、解压
- tar -zxvf boost_1_53_0.tar.gz
得到一个文件夹 boost_1_53_0, 拷贝其子目录 boost 到以下路径
- /usr/local/include/
二、编写读取解析ini的类文件
ini.h
- /*
- * File: ini.h
- * Author: tsxw24@gmail.com
- *
- * Created on 2013年3月18日, 下午2:51
- */
- #ifndef INI_H
- #define INI_H
- #include <boost/property_tree/ptree.hpp>
- #include <boost/property_tree/ini_parser.hpp>
- #include <string>
- using namespace std;
- class Ini{
- public:
- Ini(string ini_file);
- string get(string path);
- short int errCode();
- private:
- short int err_code;
- boost::property_tree::ptree m_pt;
- };
- #endif /* INI_H */
ini.cpp
- #include "ini.h"
- Ini::Ini(string ini_file){
- if (access(ini_file.c_str(), 0) == 0) {
- this->err_code = 0;
- boost::property_tree::ini_parser::read_ini(ini_file, this->m_pt);
- } else {
- this->err_code = 1;
- }
- }
- short Ini::errCode(){
- return this->err_code;
- }
- string Ini::get(string path){
- if (this->err_code == 0) {
- return this->m_pt.get<string>(path);
- } else {
- return "";
- }
- }
三、测试
main.cpp
- #include <cstdlib>
- #include <stdio.h>
- #include <iostream>
- #include <string>
- #include "ini.h"
- using namespace std;
- /*
- *
- */
- int main(int argc, char** argv) {
- string ini_file = "/home/share/code/CppClass/test1.ini";
- Ini ini(ini_file);
- cout<<ini.get("public.abc")<<endl;
- return 0;
- }
C++ 中使用boost::property_tree读取解析ini文件的更多相关文章
- boost::property_tree读取解析ini文件--推荐
boost::property_tree读取解析ini文件 #include "stdafx.h" #include <iostream> #include <b ...
- boost::property_tree读取解析.xml文件
boost::property_tree读取解析.xml文件 1)read_xml 支持中文路径 boost::property_tree::wptree wpt; std::locale:: ...
- 实战parse_ini_file()及扩展函数解析ini文件完整版
文章来源:PHP开发学习门户 地址:http://www.phpthinking.com/archives/587 在PHP站点开发的过程中,往往会用到读取ini參数配置文件,比方须要訪问一些复杂的借 ...
- shiro解析ini文件
来吧,看看shiro是怎么解析ini文件的,这里假设ini文件在classpath下,名字叫做shiro.ini Factory<org.apache.shiro.mgt.SecurityMan ...
- python解析ini文件
python解析ini文件 使用configparser - Configuration file parser sections() add_section(section) has_section ...
- 解决ini-parser解析ini文件中文乱码问题
rickyah/ini-parser 是一个.net 平台解析ini文件的库,当ini文件中含有中文字符时会乱码. 解决:将文件通过Editplus 等文本编辑工具保存为 utf-8 + bom 格式 ...
- boost::property_tree 读取ini配置
应用场景: 在后端服务器项目开发中,需要初始化一个Socket服务器,需要IP地址与对应端口号等参数:另外还可能因为对接数据库,就还需要数据库的相关配置参数,如我使用的是MySql数据库,就需要数据库 ...
- boost.property_tree读取中文乱码问题正确的解决方式
开发项目的时候在使用boost,在宽字符下遇到中文乱码问题 上网上看大家都是先转成utf8在进行解析的,例如: http://blog.csdn.net/hu_jiangan/article/deta ...
- C#中选中指定文件并读取类似ini文件的内容
一.背景 由于项目中需要去读取设备的配置信息,配置文件的内容和INI配置文件的格式类似,所以可以按照INI文件的方式来处理.涉及如何打开一个文件,获取打开的文件的路径问题,并读取选中的文件里边的内容. ...
随机推荐
- 5.对象创建型模式-原型PROTOTYPE
原型:用原型实例指定创建对象的种类,并且通过拷贝这些原型创建新的对象. 原型实现:1.用于创建对象的具体类必须实现clone()操作,用于对象克隆自己以生成新的对象.下面通过原型来实现一个抽象工厂Ma ...
- 推荐font-size的单位 % em单位
在如今这个提倡可用性设计以及用户体验设计的网络时代,CSS也是要一同参与其中的.大部分人在CSS代码编写中总是先对整体定义字体尺寸,中文情况下一般为12px,而其实这样以来在通过IE顶部菜单中的“察看 ...
- 雪佛兰Suburban_百度百科
雪佛兰Suburban_百度百科 雪佛兰Suburban
- 【JUnit4.10源码分析】5 Statement
假设要评选JUnit中最最重要的类型.或者说核心,无疑是org.junit.runners.model.Statement.Runner等类型看起来热闹而已. package org.junit.ru ...
- 二分图最大匹配 hdoj 1045
题目:hdoj1045 题意:给出一个图.当中有 . 和 X 两种,. 为通路,X表示墙,在当中放炸弹,然后炸弹不能穿过墙.问你最多在图中能够放多少个炸弹? 分析:这道题目是在上海邀请赛的题目的数据简 ...
- c++,基类声明的指针变量和引用类型变量可以指向派 生类的对象
基类声明的指针变量和引用类型变量可以指向派生类的对象,而反过来派生类的指针却不能指向基类变量. 这与基类和派生类之间,被允许的赋值方向是相反的. 但是从逻辑上很容易推敲其合理性.
- CentOS下安装两个或多个Tomcat7
链接地址:http://lcbk.net/tomcat/1407.html 首先安装JDK 安装之前检查下是否已经安装了openJDK,如果已安装,建议用yum remove 卸载掉. [root@b ...
- [Swust OJ 247]--皇帝的新衣(组合数+Lucas定理)
题目链接:http://acm.swust.edu.cn/problem/0247/ Time limit(ms): 1000 Memory limit(kb): 65535 Descriptio ...
- BZOJ 1412: [ZJOI2009]狼和羊的故事( 最小割 )
显然是最小割...把狼的领地连S, 羊的领地连T, 然后中间再连边, 跑最大流就OK了 -------------------------------------------------------- ...
- 编写存储过程导出oracle表数据到多个文本文件
1.测试表和数据: create table test(id )); begin .. loop insert into test values(k,'test'||k); end loop; end ...