提升ptree数字数组 [英] Boost ptree array of numbers
问题描述
我使用以下代码创建数字数组。
运行以下代码后,我得到以下结果:
{
: 1.100000,
: 2.200000,
: 3.300000
}
这很好,除了我想要的结果必须是数字数组而不是串。通过 boost :: property_tree :: ptree(x)
直接添加数字也给我一个错误。如何产生我的输出json结果?
{
:1.100000,
: 2.200000,
:3.300000
}
代码:
#include< iostream>
#include< boost / property_tree / ptree.hpp>
#include< boost / property_tree / json_parser.hpp>
int main()
{
boost :: property_tree :: ptree pt;
std :: vector< double> Vec = {1.1,2.2,3.3};
for(double x:Vec)
{
std :: string x_string = std :: to_string(x);
pt.push_back(
std :: make_pair(,
boost :: property_tree :: ptree(x_string)));
}
boost :: property_tree :: json_parser :: write_json(std :: cout,pt);
std :: cout<< std :: endl;
返回0;
}
PTree没有此类功能。
一切都是序列化格式的文本。即使选择的后端格式可以支持(有限)键入的数据。
文档
我一直在重申:
Boost没有没有具有XML库。
Boost没有没有具有XML库。 JSON库。
Boost有一个属性树库。它处理属性树。不是JSON,XML或其他任何格式。
I use the following code to create an array of the numbers.
After running the following code, I reveive the following results:
{
"": "1.100000",
"": "2.200000",
"": "3.300000"
}
It is good except for my desired result has to be an array of numbers not string. Adding a number directly by boost::property_tree::ptree(x)
gives me an error too. How can I produce my output json results?
{
"": 1.100000,
"": 2.200000,
"": 3.300000
}
Code:
#include <iostream>
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/json_parser.hpp>
int main()
{
boost::property_tree::ptree pt;
std::vector<double> Vec={1.1,2.2,3.3};
for(double x:Vec)
{
std::string x_string=std::to_string(x);
pt.push_back(
std::make_pair("",
boost::property_tree::ptree(x_string)) );
}
boost::property_tree::json_parser::write_json(std::cout, pt);
std::cout<<std::endl;
return 0;
}
PTree has no such features.
Everything is text in the serialized formats. Even if the chosen backend format could support (limited) typed data.
Documentation proof:
As I keep re-stating:
Boost does not have an XML library.
Boost does not have a JSON library.
Boost has a Property Tree library. It deals with Property Trees. Not JSON, XML or whatever else.
这篇关于提升ptree数字数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!