用BOOST读配置文件
来源:互联网 发布:球状闪电刘慈欣 知乎 编辑:程序博客网 时间:2024/05/20 11:20
#include <string>
#include <iostream>
using namespace std;
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/ini_parser.hpp>
class CBoostConfigFile
{
public:
typedef boost::property_tree::ptree str_ptree;
private:
string m_filename;
boost::property_tree::ptree m_protree;
public:
CBoostConfigFile(string filename){
m_filename=filename;
try{
boost::property_tree::ini_parser::read_ini(m_filename, m_protree);
}catch(std::exception &e)
{
std::cout<<e.what()<<std::endl;
}
};
virtual ~CBoostConfigFile(){};
bool GetParam(const char *name,string ¶m)
{
if(m_filename.length()==0)
return false;
try{
param = m_protree.get<string>(name);
}catch(std::exception &e)
{
std::cout<<e.what()<<std::endl;
return false;
}
return true;
}
bool GetParam(const char *name,long ¶m)
{
if(m_filename.length()==0)
return false;
try{
param = m_protree.get<long>(name);
}catch(std::exception &e)
{
std::cout<<e.what()<<std::endl;
param=0;
return false;
}
return true;
}
bool GetParam(const char *name,int ¶m)
{
if(m_filename.length()==0)
return false;
try{
param = m_protree.get<int>(name);
}catch(std::exception &e)
{
std::cout<<e.what()<<std::endl;
param=0;
return false;
}
return true;
}
bool GetChile(const char *name,str_ptree&chiletree)
{
try{
chiletree= m_protree.get_child(name);
}catch(std::exception &e)
{
std::cout<<e.what()<<std::endl;
return false;
}
return true;
}
};
test:
string str;
config.GetParam("aa.1",str);
printf("getstr:%s\r\n",str.c_str());
config.GetParam("bb",str);
printf("cqnum:%s\r\n",str.c_str());
boost::property_tree::ptree child1;
config.GetChile("config1",child1);
for(boost::property_tree::ptree::iterator pos=child1.begin(); pos != child1.end(); ++pos)
{
string name=pos->second.data();
string value=pos->first.data();
printf("%s\t%s\r\n",name.c_str(),value.c_str());
}
- 用BOOST读配置文件
- 用boost中的property_tree实现配置文件
- Boost读取XML配置文件
- boost 操作配置文件
- Boost property_tree 解析配置文件
- c++用boost的property_tree库来操作xml配置文件
- 使用boost库解析xml配置文件
- 使用boost property_tree 生成XML配置文件
- 使用 boost::property_tree::ptree 读取配置文件
- boost之program_options库,解析命令行参数、读取配置文件
- boost之program_options库,解析命令行参数、读取配置文件
- boost库之ptree的ini配置文件解析
- boost库之ptree的ini配置文件解析
- boost之program_options库,解析命令行参数、读取配置文件
- boost之program_options库,解析命令行参数、读取配置文件
- 简单使用boost property_tree组件获取配置文件信息
- 用boost::bind构造boost::coroutine
- boost编译用bjam
- Linux下锐捷的配置
- Android如何运行真机在eclipse上调试应用
- “安装程序无法定位现有系统分区,也无法创建新的系统分区”-安装win7的提示
- 策略模式实现支持多种类数据库的DBHelp(推荐--arvin)
- PO RELEASE 采购订单审核(支持多级审核)
- 用BOOST读配置文件
- Ucos学习之时间管理
- Sql语句
- 抓住3G android人才缺口的机遇,让薪水飞一会儿!
- 设置(Settings)
- 关于sql的一点经验
- CUDA计算能力的一个衡量标准
- INI file
- 类似WEBQQ的一套开源代码