相关疑难解决方法(0)

如何获取boost json以使用正确的数据类型

当我put_value使用int时,它会以字符串形式写入。有人知道如何将其打印为int吗?

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

using boost::property_tree::ptree;
using namespace std;

int main(int argc, char* argv[]) {

    ptree node;
    node.put("string", "text here");
    node.put("int", 1);//outputs as "1" and should be 1
    write_json(cout, node, false);//{"string":"text here","int":"1"}

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

c++ json boost boost-propertytree

3
推荐指数
1
解决办法
1955
查看次数

标签 统计

boost ×1

boost-propertytree ×1

c++ ×1

json ×1