Compilation error with boost::property_tree::xml_writer_settings
Asked Answered
Y

1

11

In order to pretty print my XML output with boost::property_tree, I wrote the following code:

#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/xml_parser.hpp>

int main()
{
    std::string filename = "test.xml";
    boost::property_tree::ptree pt;
    pt.put("some.path.value", "hello");

    boost::property_tree::xml_writer_settings<char> settings('\t', 1);
    write_xml(filename, pt, settings);
}

Unfortunately I have this error and I can't find any information about it:

/usr/local/include/boost/property_tree/detail/xml_parser_writer_settings.hpp:38:19: error: type 'char' cannot be used prior to '::' because it has no members
    typedef typename Str::value_type Ch;
                     ^

Any idea?

Yukyukaghir answered 31/3, 2015 at 14:13 Comment(4)
This document may help you, but I'm not sureKela
this is the header I'm usingYukyukaghir
Next time: Please include relevant code in the question, so we can ace the answer, instead of drawing out "thanks but..." in the comments :)Aparejo
Yes I will add it right nowYukyukaghir
A
13

I'd use the helper function

std::ofstream file("test.xml");

boost::property_tree::ptree pt;    
pt.put("some.value", "test");

boost::property_tree::write_xml(
   file, pt,
   boost::property_tree::xml_writer_make_settings<std::string>('\t', 1));
Aparejo answered 31/3, 2015 at 14:27 Comment(5)
It works but how can I use it with write_xml? When writing write_xml(filename, pt, boost::property_tree::xml_writer_make_settings<std::string>('\t', 1)) I have the following error: no matching function for call to 'write_xmlYukyukaghir
@MartinDelille You need to pass a stream, not a filename. The documentation is patient :) boost.org/doc/libs/1_57_0/doc/html/boost/property_tree/… (also funny you truncated the message because now I'm having to guess what the types of filename and pt are).Aparejo
There is an issue with changing from <char> to <std::string> it only works if you are building on a 64bit, otherwise if you are building on 32bit and try to use <std::string> then you will get above described error, however if you are building on 64bit you will not get the error -- this assuming that you used a stream and not filenameRestriction
@Restriction that makes little sense. It seems like you may be conflating character encoding and build architecture.Aparejo
@sehe, I agree it makes little sense, none the less it is the fact - try it outRestriction

© 2022 - 2024 — McMap. All rights reserved.