Why is my JSON to XML converter using BOOST Property Tree giving a segmentation fault?

Monday, June 30, 2014


#include <boost/property_tree/json_parser.hpp>
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/xml_parser.hpp>
#include <iostream>
#include <fstream>

using namespace std;

int main () {
ifstream file;
boost::property_tree::ptree pt;
file.open ("json.txt");

if (!file)
cout << "problem";

//std::stringstream ss;
//ss << "{ \"root\": { \"values\": [1, 2, 3, 4, 5 ] } }";
boost::property_tree::read_json(file, pt);

ofstream filexml ("xml.txt");

boost::property_tree::write_xml(filexml, pt);

cout <<"done";
return 0;
}


However if I use the stringstream, it succeeds. The contents of the json.txt file are what is seen in the comments for stringstream. Can you point out what I'm doing wrong ?







http://ift.tt/1x8P0zQ