简体   繁体   English

Boost Json写错误:没有匹配的函数来调用'boost :: property_tree :: basic_ptree

[英]Boost Json Write error: no matching function for call to ‘boost::property_tree::basic_ptree<std::__cxx11

I am trying to write Json data to a string using Boost library but I am facing a compilation error: 我正在尝试使用Boost库将Json数据写入字符串,但遇到编译错误:

error: no matching function for call to ‘boost::property_tree::basic_ptree<std::__cxx11::basic_string<char>, std::__cxx11::basic_string<char> >::push_back(std::pair<const char*, const char*>)

My c++ code is 我的C ++代码是

#include <fstream>
#include <iostream>

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

namespace pt = boost::property_tree;

int main()
{
  std::string enc = "Enoded data";

    pt::ptree root;
    pt::write_json(std::cout, root);

    pt::ptree image_node;
    image_node.push_back(std::make_pair("content", enc));
    root.add_child("image", image_node);

    pt::ptree features_node;
    features_node.push_back(std::make_pair("type", "LABEL_DETECTION"));
    features_node.push_back(std::make_pair("maxResults", 1)); 
    root.add_child("features", features_node);
    pt::write_json(std::cout, root);
    return 0;
}

boost::property_tree::ptree::push_back takes a boost::property_tree::ptree::value_type as parameter, which is not the same as std::pair<const char*, const char*> . boost::property_tree::ptree::push_backboost::property_tree::ptree::value_type作为参数,这与std::pair<const char*, const char*> So, you'd need eg. 因此,您需要例如。 :

features_node.push_back(pt::ptree::value_type("type", pt::ptree("LABEL_DETECTION")));

Or better yet, just use boost::property_tree::ptree::put : 或者更好的是,只需使用boost::property_tree::ptree::put

pt::ptree root;

root.put("image.content", enc);
root.put("features.type", "LABEL_DETECTION");
root.put("features.maxResults", 1);

pt::write_json(std::cout, root);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 没有匹配的函数来调用&#39;boost :: property_tree :: ptree_bad_data :: ptree_bad_data() - no matching function for call to ‘boost::property_tree::ptree_bad_data::ptree_bad_data() 错误:没有匹配的函数调用&#39;std :: map <std::__cxx11::basic_string<char> - error: no matching function for call to ‘std::map<std::__cxx11::basic_string<char> 错误:没有匹配的函数调用&#39;std::basic_ifstream<char> ::basic_ifstream(std::__cxx11::string&amp;)&#39; - error: no matching function for call to 'std::basic_ifstream<char>::basic_ifstream(std::__cxx11::string&)' boost :: property_tree :: ptree序列化和反序列化 - boost::property_tree::ptree serializing and deserializing 移动boost :: property_tree :: ptree的构造函数 - Move constructor for boost::property_tree::ptree boost::property_tree::ptree 线程安全吗? - is boost::property_tree::ptree thread safe? 错误:没有匹配函数来调用&#39;std :: vector <std::__cxx11::basic_string<char> &gt; ::的push_back(INT&)” - error: no matching function for call to ‘std::vector<std::__cxx11::basic_string<char> >::push_back(int&)’ 错误:没有匹配的函数调用&#39;std::__cxx11::basic_string<char> ::basic_string(int&amp;)&#39; - error: no matching function for call to ‘std::__cxx11::basic_string<char>::basic_string(int&)’ 从boost :: property_tree :: ptree :: iterator获取ptree - Getting the ptree from boost::property_tree::ptree::iterator C++ 错误:没有匹配的函数调用&#39;std::__cxx11::basic_string<char> ::附加<int> (int, int)&#39; - c++ error: no matching function for call to ‘std::__cxx11::basic_string<char>::append<int>(int, int)’
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM