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正则:零宽断言

    JavaScript正则表达式零宽断言 var str="abnsdfZL1234nvcncZL123456kjlvjkl"var reg=/ZL(\d{4}|\d{6})(?!\ ...

  2. How can you determine how much disk space a particular MySQL table is taking up?

    http://stackoverflow.com/questions/6474591/how-can-you-determine-how-much-disk-space-a-particular-my ...

  3. Nginx日志增长过快详细分析

    前言: Nginx日志里面Mobileweb_access.log增长特别大,一天上百兆,将近100W的访问记录,按照我们目前的规模,热点用户才500个左右,就算人人用手机app访问,怎么可能会有这么 ...

  4. 基于PCA的人脸识别步骤

    代码下载:基于PCA(主成分分析)的人脸识别 人脸识别是一个有监督学习过程,首先利用训练集构造一个人脸模型,然后将测试集与训练集进行匹配,找到与之对应的训练集头像.最容易的方式是直接利用欧式距离计算测 ...

  5. Roseonly:互联网轻奢品牌之路-搜狐IT

    Roseonly:互联网轻奢品牌之路-搜狐IT Roseonly:互联网轻奢品牌之路

  6. Linux UDEV和为MySQL InnoDB共享表空间配置裸设备

    ⑴ UDEV 基础         udev 可管理保存在/dev 目录下的文件.文件只有在接入相应设备后才会生成.设备被拔出后自动删除     它还允许用户添加规则.以便修改/dev中默认的名称和权 ...

  7. 怎样在VirtualBox 虚拟机中挂载共享目录

    啊.好长时间没写博客了.近期有点忙~~ 不得不说 VirtualBox 对于一些不想装非常多个系统又非常想实验新系统的人来说确实是神器: 哈哈.个人还是比較爱玩这些个各种各样的Linux 发型版的,可 ...

  8. iOS之UITableViewCell左右滑动效果

    首先在 UITableViewCell.h 中声明一个代理 @protocol UITableViewCellSlideDelegate <UITableViewDelegate> @op ...

  9. 【linux】 linux gpio操作

    欢迎转载,转载时需保留作者信息,谢谢. 邮箱:tangzhongp@163.com 博客园地址:http://www.cnblogs.com/embedded-tzp Csdn博客地址:http:// ...

  10. c++,派生类对象可以对基类赋值,基类对派生类不可以赋值

    派生类对象可以对基类对象赋值,赋值时属于派生类独有的部分就舍弃不用. #include <iostream> using namespace std; class DemoA { publ ...