BOOST1.41带来的新玩意property tree--很好的配置文件处理类库
2009-12-03 17:58
471 查看
首先是无耻的抄袭了boost文档中的例子:
boost_1_41_0/libs/property_tree/examples/debug_settings.cpp
……
关键是修改的save函数中的一点东西(红色的两行).这样它就可以将xml文件的编码格式修改为中文了.嘿嘿.使用的是GB18030编码.
使用C++方便的操作xml方式的配置文件.感觉这应该是对ini配置文件的一次比较好的升级.还是boost提供的.真不错.
待考察稳定了后,将陆续增加到自己的应用程序开发中.
void debug_settings::save(const std::string &filename)
{
// Create empty property tree object
using boost::property_tree::ptree;
ptree pt;
// Put log filename in property tree
pt.put("debug.filename", m_file);
// Put debug level in property tree
pt.put("debug.level", m_level);
pt.add("debug.modules.module", "abc");
pt.add("debug.modules.module", "def");
pt.add("debug.modules.module", "我是中国人");
// Iterate over modules in set and put them in property
// tree. Note that put function places new key at the
// end of list of keys. This is fine in most of the
// situations. If you want to place item at some other
// place (i.e. at front or somewhere in the middle),
// this can be achieved using combination of insert
// and put_value functions
BOOST_FOREACH(const std::string &name, m_modules)
{
pt.add("debug.modules.module", name);
}
// Write property tree to XML file
// 通过定制的xml设置类将xml文件的编码集设置为gb18030.这样就不必将xml文件转换为utf-8了
boost::property_tree::xml_parser::xml_writer_settings ss('*' ,0,"gb18030");
write_xml(filename, pt,std::locale(),ss);
}
boost_1_41_0/libs/property_tree/examples/debug_settings.cpp
……
关键是修改的save函数中的一点东西(红色的两行).这样它就可以将xml文件的编码格式修改为中文了.嘿嘿.使用的是GB18030编码.
使用C++方便的操作xml方式的配置文件.感觉这应该是对ini配置文件的一次比较好的升级.还是boost提供的.真不错.
待考察稳定了后,将陆续增加到自己的应用程序开发中.
void debug_settings::save(const std::string &filename)
{
// Create empty property tree object
using boost::property_tree::ptree;
ptree pt;
// Put log filename in property tree
pt.put("debug.filename", m_file);
// Put debug level in property tree
pt.put("debug.level", m_level);
pt.add("debug.modules.module", "abc");
pt.add("debug.modules.module", "def");
pt.add("debug.modules.module", "我是中国人");
// Iterate over modules in set and put them in property
// tree. Note that put function places new key at the
// end of list of keys. This is fine in most of the
// situations. If you want to place item at some other
// place (i.e. at front or somewhere in the middle),
// this can be achieved using combination of insert
// and put_value functions
BOOST_FOREACH(const std::string &name, m_modules)
{
pt.add("debug.modules.module", name);
}
// Write property tree to XML file
// 通过定制的xml设置类将xml文件的编码集设置为gb18030.这样就不必将xml文件转换为utf-8了
boost::property_tree::xml_parser::xml_writer_settings ss('*' ,0,"gb18030");
write_xml(filename, pt,std::locale(),ss);
}
相关文章推荐
- 使用 boost::property_tree::ptree 读取配置文件
- 使用boost中的property_tree实现配置文件
- 使用boost中的property_tree实现配置文件
- 用boost中的property_tree实现配置文件
- Boost学习笔记(四)---利用boost::property_tree;读写xml文件,保存文件
- 使用Boost.PropertyTree处理XML、JSON和INI数据
- c++用boost的property_tree库来操作xml配置文件
- Python之xml文档及配置文件处理(ElementTree模块、ConfigParser模块)
- 使用Boost.PropertyTree处理XML、JSON和INI数据 - 做一个优雅的程序员 - 博客频道 - CSDN.NET
- boost 之property_tree操作xml文件
- boost::property_tree读取解析ini文件--推荐
- boost::property_tree读取解析ini文件--推荐
- 使用Boost.PropertyTree处理XML、JSON和INI数据
- boost::property_tree读取解析.xml文件
- boost::property_tree读取解析.xml文件
- boost使用property_tree/json_parser处理包含中文字符的UTF8时异常的解决办法
- boost::property_tree读取解析.xml文件
- 在处理向该请求提供服务所需的配置文件时出错。请检查下面的特定错误详细信息并适当地修改配置文件。
- property配置文件读取工具类
- 使用 LibXML2 处理配置文件