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. (IOS)CoreLocation 和 MapKit 的应用

    CoreLocation是控制GPS硬件获取地理坐标信息的系统类库,而MapKit是系统地图的工具包,将两者结合使用可以实现不同的地图功能. 1.CoreLocation 在CoreLocation中 ...

  2. 转:JS线程和JS阻塞页面加载的问题

    前几日写了一篇文章,介绍了js阻塞页面加载的问题.当时是通过例子来验证的.今天,我介绍一下浏览器内核,从原理上介绍一下js阻塞页面加载的原因. 浏览器的内核是多线程的,它们在内核制控下相互配合以保持同 ...

  3. PROPAGATION_REQUIRED

    PROPAGATION_REQUIRED (2009-05-13 13:26:52) 转载▼   事务传播行为种类 Spring在TransactionDefinition接口中规定了7种类型的事务传 ...

  4. Windows Azure 社区新闻综述(#77 版)

    欢迎查看最新版本的每周综述,其中包含有关云计算和 Windows Azure 的社区推动新闻.内容和对话.以下是本周的亮点. 文章.视频和博客文章 ·   文章: Windows Azure 表存储简 ...

  5. zzuli生化危机(dfs)

    生化危机 Time Limit: 1 Sec  Memory Limit: 128 MB Submit: 73  Solved: 21SubmitStatusWeb Board Description ...

  6. Android网络开发之用tcpdump抓包

    Android开发过程中,当涉及到网络通信的时候,有一些字段须要抓包获取.我之前由于SSDP设备发现的包头格式没有写对,经过抓包分析和标准包头对照发现了这个困扰我非常久的问题.总之,掌握在Androi ...

  7. Codeforces Round #250 (Div. 2)—A. The Child and Homework

         好题啊,被HACK了.曾经做题都是人数越来越多.这次比赛 PASS人数 从2000直掉 1000人  被HACK  1000多人! ! ! ! 没见过的科技啊 1 2 4 8 这组数 被黑的 ...

  8. .NET通用权限系统快速开发框架源代码

    有兴趣的朋友欢迎加群讨论:312677516 一.开发技术:B/S(.NET C# ) 1.Windows XP以上 (支援最新Win 8) 2.Microsoft Visual Studio 201 ...

  9. Windows Time服务无法启动 错误5拒绝访问

    接着上次写的文章 XP和Win7设置系统自动同步系统时间方法 本文就把故障出现的过程和解决方法一共写下来,希望大家可以看到本文在解决此项服务的思路.大家以后出现类似的问题和问题可以一样使用此类方法解决 ...

  10. java.lang.IllegalStateException: No data type for node: org.hibernate.hql.ast.tree.MethodNode(尼玛,蛋疼的错误)

    java.lang.IllegalStateException: No data type for node: org.hibernate.hql.ast.tree.MethodNode   \-[M ...