我正在尝试使用Boost的property_tree解析器和C++ 11代码解析JSON(我的系统是Debian Wheezy,gcc 4.7.2和Boost 1.49).我尝试了以下代码基于使用boost序列化和反序列化json:
#include <map>
#include <sstream>
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/json_parser.hpp>
using boost::property_tree::ptree; using boost::property_tree::read_json; using boost::property_tree::write_json;
void example() {
// Write json.
ptree pt;
pt.put ("foo", "bar");
std::ostringstream buf;
write_json (buf, pt, false);
std::string json = buf.str(); // {"foo":"bar"}
// Read json.
ptree pt2;
std::istringstream is (json);
read_json (is, pt2);
std::string foo = pt2.get<std::string> ("foo");
}
Run Code Online (Sandbox Code Playgroud)
如果我用g++ -std=c++03 -c' everything is fine. However, I also want to use C++11 features (which the code in …