boost格式化输出xml
我的boost为1.56而不是1.55
boost在xml的例子给出了一段写xml文件的代码,我简化如下:
void debug_settings::save(const std::string &filename)
{
using boost::property_tree::ptree;
ptree pt; pt.put("debug.filename", m_file);
pt.put("debug.level", m_level); write_xml(filename, pt);
}
这段代码写出来的格式非常难看,没有缩进的。于是在网上查找了下,需要改成下面的样子:
void debug_settings::save(const std::string &filename)
{
using boost::property_tree::ptree;
ptree pt; pt.put("debug.filename", m_file);
pt.put("debug.level", m_level); boost::property_tree::xml_writer_settings<char> settings('\t',);
write_xml(filename, pt,std::local(),settings);
}
意思是缩进1个\t,结果报了一大堆错误:
In instantiation of 'class boost::property_tree::xml_parser::xml_writer_settings<char>':
../../game_server/common/CServerSetting.cpp::: required from here
../../game_server/libraries/boost_1_56_0/boost/property_tree/detail/xml_parser_writer_settings.hpp::: error: 'char' is not a class, struct, or union type
typedef typename Str::value_type Ch;
本人水平在菜,没见过此类错误。去百度,也找不到类似的结果。看xml_parser_writer_settings的源代码,也看不懂。白白浪费了几个小时,终于受不了,翻出去请教google,很快找到了相关的解决方案:
http://www.pcl-users.org/PCL-compilation-errors-Please-help-me-td4035209.html
This is because there is a breaking API change in the boost 1.56. property_tree, as compared to boost 1.55.. For more reference, see an issue described here: link.
I fixed this by modifying:
boost::property_tree::xml_writer_settings<char> settings ('\t', );
write_xml (filename, pt, std::locale (), settings);
To:
auto settings = boost::property_tree::xml_writer_make_settings<std::string> ('\t', );
write_xml (filename, pt, std::locale (), settings);
In the or so places this occurs...
Thanks,
McDamon
http://lists.boost.org/boost-users/2014/08/82693.php
Dear all, with the release of Boost 1.56, on Ubuntu 14.04 (g++ 4.8., bit),
code like the following suddenly fails to compile: pt::xml_writer_settings<char> settings('\t', );
pt::write_xml(someFileName, ptr_out, std::locale(), settings); "pt" is obviously an alias for boost::property_tree. The error message
I'm getting is /opt/boost156/include/boost/property_tree/detail/xml_parser_writer_settings.hpp:::
error: 'char' is not a class, struct, or union type
typedef typename Str::value_type Ch; I can see the following possibly relevant change in property_tree: In Boost 1.55, from xml_parser.hpp:
----------------------------------- template<typename Ptree>
void write_xml(
const std::string &
, const Ptree &
, const std::locale & = std::locale()
, const xml_writer_settings<typename Ptree::key_type::value_type >& =
xml_writer_settings<typename Ptree::key_type::value_type >()
); In Boost 1.56, same header:
--------------------------- template<typename Ptree>
void write_xml(
const std::string &
, const Ptree &
, const std::locale & = std::locale()
, const xml_writer_settings<typename Ptree::key_type > &
= xml_writer_settings<typename Ptree::key_type >()
); So xml_writer_settings is now given a Ptree::key_type instead of a
Ptree::key_type::value_type which I assume is the reason for the above
error. Is there a portable way to specify the type of indention character in
write_xml ? Best Regards,
Beet
由于我没有启用C++11,改为这样写
boost::property_tree::xml_writer_settings<string> settings =
boost::property_tree::xml_writer_make_settings<string> (' ', );
write_xml( DEFAULTCONFIG,pt,std::locale(),settings );
问题解决。
PS:大伙以后搜索代码用这个http://www.gfsoso.com/。百度找找电影院什么的就好,搜代码实现是不靠谱。
boost格式化输出xml的更多相关文章
- XStream、JAXB 日期(Date)、数字(Number)格式化输出xml
XStream.Jaxb是java中用于对象xml序列化/反序列化 的经典开源项目,利用它们将对象转换成xml时,经常会遇到日期(Date).数字按指定格式输出的需求,下面是使用示例: 一.日期字段格 ...
- JAXP使用Stax API时格式化输出XML
最近项目中需要生成XBRL instance,对于XML读写和验证进行了一些学习.由于Stax API不支持格式化输出,默认全都写在一行上,网上也没有搜到现成的东西,自己写了一个格式化输出的帮助类. ...
- JAXP使用Stax API时格式化输出XML 2
之前实现的一个版本:http://www.cnblogs.com/lyhtbc/p/jaxp-pretty-format-validate-validation-stax-stax2.html 这个版 ...
- WPF中任意Object的XAML代码格式化输出
原文:WPF中任意Object的XAML代码格式化输出 有时候,我们需要将WPF中的控件自身的XAML代码输出成文本,那么,我们可以使用System.Windows.Markup.XamlWriter ...
- Java - 格式化输出JSON字符串的两种方式
目录 1 使用阿里的fastjson 1.1 项目的pom.xml依赖 1.2 Java示例代码 2 使用谷歌的gson 2.1 项目的pom.xml依赖 2.2 Java示例代码 1 使用阿里的fa ...
- .NET宝藏API之:OutputFormatter,格式化输出对象
相信大家在项目中都用过统一响应参数模板. 先声明一个响应模板类: public class ResponseDto { public int code { get; set; } public str ...
- python的print函数的格式化输出
使用print函数的时候,可以像C一样格式化输出,同时还支持参数化输出 print('%s' % ("CooMark")) print('整数|%d|' % (123)) prin ...
- python学习笔记(基础二:注释、用户输入、格式化输出)
注释 单行:# 多行:上下各用3个连续单引号或双引号 3个引号除了多行注释,还可以打印多行 举例: msg = ''' name = "Alex Li" name2 = name ...
- cout 格式化输出
一直习惯于C语言的printf函数来打印,突然有一天要用cout来打印,发现有点不适应. 原来cout也是有格式化输出的. 首先要引入头文件 #include<iostream> // 在 ...
随机推荐
- UGUI 下拉滚动框
开始制作好友系统了, 发现有一个UI跟QQ的面板一模一样. 于是就写了一个公共的下拉滚动框.需要把按钮的中心点(pivot.y = 1),描点为最上方 直接上图吧 代码如下: using UnityE ...
- 升级IOS9,提示滑动升级,卡在password锁屏界面,无反应了
注:升级之前一定要把锁屏password取消掉 若遇上述问题.可通过进入DFU 模式解决 进入DFU具体步骤.(进入成功后,屏幕为全黑) 注:在进入DFU操作时务必与电脑连接好数据线. 1.按住pow ...
- 奔五的人学IOS:swift练手与csdn,最近学习总结
早在五月份就准备開始学习ios开发,当时还是oc,学习了几天,最终不得其法.到了ios8开放,再加swift的出现.从10月份開始.最终找到了一些技巧,学习起来还算略有心得. 今天把我在学习swift ...
- AssemblyInfo.cs文件的作用
在asp.net中有一个配置文件AssemblyInfo.cs主要用来设定生成的有关程序集的常规信息dll文件的一些參数,以下是默认的AssemblyInfo.cs文件的内容详细介绍 //是否符合公共 ...
- BNU10805:矩形神码的
我们都知道,矩形是由两条对角线的,没错吧?(谜之声:这不是显然么!)这两条线的长度也是相等的,没错吧?(谜之声:这不废话么!)然后我们给定一条对角线的起始点和终止点的坐标,然后给定另一个对角线和他的夹 ...
- phoneGap开发环境搭建(android)
1. 首先安装nodejs (http://nodejs.org/) 2. 然后在命令行输入 npm 回车 假设出现下图: 则表示成功安装 3. 安装 npm install -g cordov ...
- python查看删除你微信的账号
#应用环境:python2.7 #!/usr/bin/env python # coding=utf-8 from __future__ import print_function import os ...
- ewebeditor下利用ckplayer增加html5 (mp4)全平台的支持
学校数字化平台富文本编辑器一直用的ewebeditor,应该说非常的好,支持常用office文档的直接导入,极大的方便了老师们资料的上传,最近在规划整个数字化校园向全平台改版,框架采用bootstra ...
- FpSpread添加标注
先看效果 实现: FarPoint.Web.Spread.StyleInfo Errorcss = new FarPoint.Web.Spread.StyleInfo(); Errorcss.Bord ...
- Android ----------获取各种路径(更新中。。。。。。)
##在手机中的路径 *获取应用的路径,形式:/data/data/包名 String appDataDir = getApplicationInfo().dataDir; *获取手机数据存储路径,即/ ...