boost 官网 http://www.boost.org/

下载页面 http://sourceforge.net/projects/boost/files/boost/1.53.0/

我下载的是 boost_1_53_0.tar.gz

使用系统  ubuntu 12.10

一、解压

  1. tar -zxvf  boost_1_53_0.tar.gz

得到一个文件夹 boost_1_53_0,  拷贝其子目录 boost 到以下路径

  1. /usr/local/include/

二、编写读取解析ini的类文件

ini.h

  1. /*
  2. * File:   ini.h
  3. * Author: tsxw24@gmail.com
  4. *
  5. * Created on 2013年3月18日, 下午2:51
  6. */
  7. #ifndef INI_H
  8. #define INI_H
  9. #include <boost/property_tree/ptree.hpp>
  10. #include <boost/property_tree/ini_parser.hpp>
  11. #include <string>
  12. using namespace std;
  13. class Ini{
  14. public:
  15. Ini(string ini_file);
  16. string get(string path);
  17. short int errCode();
  18. private:
  19. short int err_code;
  20. boost::property_tree::ptree m_pt;
  21. };
  22. #endif  /* INI_H */

ini.cpp

  1. #include "ini.h"
  2. Ini::Ini(string ini_file){
  3. if (access(ini_file.c_str(), 0) == 0) {
  4. this->err_code = 0;
  5. boost::property_tree::ini_parser::read_ini(ini_file, this->m_pt);
  6. } else {
  7. this->err_code = 1;
  8. }
  9. }
  10. short Ini::errCode(){
  11. return this->err_code;
  12. }
  13. string Ini::get(string path){
  14. if (this->err_code == 0) {
  15. return this->m_pt.get<string>(path);
  16. } else {
  17. return "";
  18. }
  19. }

三、测试

main.cpp

    1. #include <cstdlib>
    2. #include <stdio.h>
    3. #include <iostream>
    4. #include <string>
    5. #include "ini.h"
    6. using namespace std;
    7. /*
    8. *
    9. */
    10. int main(int argc, char** argv) {
    11. string ini_file = "/home/share/code/CppClass/test1.ini";
    12. Ini ini(ini_file);
    13. cout<<ini.get("public.abc")<<endl;
    14. return 0;
    15. }

C++ 中使用boost::property_tree读取解析ini文件的更多相关文章

  1. boost::property_tree读取解析ini文件--推荐

    boost::property_tree读取解析ini文件 #include "stdafx.h" #include <iostream> #include <b ...

  2. boost::property_tree读取解析.xml文件

    boost::property_tree读取解析.xml文件 1)read_xml 支持中文路径  boost::property_tree::wptree wpt;    std::locale:: ...

  3. 实战parse_ini_file()及扩展函数解析ini文件完整版

    文章来源:PHP开发学习门户 地址:http://www.phpthinking.com/archives/587 在PHP站点开发的过程中,往往会用到读取ini參数配置文件,比方须要訪问一些复杂的借 ...

  4. shiro解析ini文件

    来吧,看看shiro是怎么解析ini文件的,这里假设ini文件在classpath下,名字叫做shiro.ini Factory<org.apache.shiro.mgt.SecurityMan ...

  5. python解析ini文件

    python解析ini文件 使用configparser - Configuration file parser sections() add_section(section) has_section ...

  6. 解决ini-parser解析ini文件中文乱码问题

    rickyah/ini-parser 是一个.net 平台解析ini文件的库,当ini文件中含有中文字符时会乱码. 解决:将文件通过Editplus 等文本编辑工具保存为 utf-8 + bom 格式 ...

  7. boost::property_tree 读取ini配置

    应用场景: 在后端服务器项目开发中,需要初始化一个Socket服务器,需要IP地址与对应端口号等参数:另外还可能因为对接数据库,就还需要数据库的相关配置参数,如我使用的是MySql数据库,就需要数据库 ...

  8. boost.property_tree读取中文乱码问题正确的解决方式

    开发项目的时候在使用boost,在宽字符下遇到中文乱码问题 上网上看大家都是先转成utf8在进行解析的,例如: http://blog.csdn.net/hu_jiangan/article/deta ...

  9. C#中选中指定文件并读取类似ini文件的内容

    一.背景 由于项目中需要去读取设备的配置信息,配置文件的内容和INI配置文件的格式类似,所以可以按照INI文件的方式来处理.涉及如何打开一个文件,获取打开的文件的路径问题,并读取选中的文件里边的内容. ...

随机推荐

  1. 瀑布流的三种实现方式(原生js+jquery+css3)

    前言 项目需求要弄个瀑布流的页面,用的是waterfall这个插件,感觉还是可以的,项目赶就没自己的动手写.最近闲来没事,就自己写个.大致思路理清楚,还是挺好实现的... 原生javascript版 ...

  2. referer htttp headers 统计信息 防盗链

    HTTP headers是HTTP请求和相应的核心模块,它承载了关于客户端浏览器.请求页面.服务器等相关信息.Referer是HTTP头中的一个属性,告诉服务器我是从哪个页面链接过来的,所携带的信息用 ...

  3. JAVA用JNI方法调用C代码实现HelloWorld

    一.首先是java运行环境的搭建,到官网下载java jdk安装即可(注意要修改环境变量).还可以顺便安装eclipse. 二.编写java代码,文件名HelloWorld.java public c ...

  4. (3)选择元素——(2)文档对象模型(The Document Object Model)

    One of the most powerful aspects of jQuery is its ability to make selecting elements in the DOM easy ...

  5. asp.net中MVC多语言包的使用

    Global.asax.cs文件 protected void Application_AcquireRequestState(object sender, EventArgs e) { if (Ht ...

  6. C#学习之------委托

    1.向窗体中添加控件的最少步骤:                 窗体的句柄为this private System.Windows.Forms.Button button1;             ...

  7. php开启虚拟域名功能

    1.开启apache的mod_rewrite功能 关闭注释 LoadModule rewrite_module modules/mod_rewrite.so 2.引入http-vhosts.conf文 ...

  8. 今天才知道mysql

    insert MySQL中的INSERT语句和标准的INSERT不太一样,在标准的SQL语句中,一次插入一条记录的INSERT语句只有一种形式.INSERT INTO tablename(列名…) V ...

  9. USACO Cow Pedigrees 【Dp】

    一道经典Dp. 定义dp[i][j] 表示由i个节点,j 层高度的累计方法数 状态转移方程为: 用i个点组成深度最多为j的二叉树的方法树等于组成左子树的方法数 乘于组成右子树的方法数再累计. & ...

  10. 使用MongoDB的开源项目(转)

    根据谷歌的搜索结果筛选出来的. 统计应用 counlty https://count.ly/ mongopress 开源CMS系统 http://www.mongopress.org/ Rubedo ...