使用boost属性树迭代json属性键和值

时间:2014-06-30 09:00:43

标签: c++ json c++11 boost

我正在尝试使用json阅读boost::property_tree文件。我已经能够读取json文件并获取属性值。现在,我试图遍历属性树中的所有属性并打印出所有键值对。我不确定如何做到这一点。我尝试过使用BOOST_FOREACH,但最终得到了编译错误。如何正确迭代属性树变量中的属性并获取它们各自的键和值?

#include <fstream>
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/json_parser.hpp>
#include <boost/foreach.hpp>
#include <exception>
#include <string>
using namespace std;

    int main(){
        boost::property_tree::ptree pt;
        boost::property_tree::read_json("./data.json", pt);
            BOOST_FOREACH(boost::property_tree::ptree::value_type &v, pt)
        {
            std::cout << v.first << ":" << v.second << std::endl;
        }
        std::cout<<pt.get<string>("name")<<std::endl;
        std::cout <<"Done"<<std::endl;
        return 1;
    }

我在行std::cout << v.first << ":" << v.second << std::endl;上收到编译错误。我正在使用g++ -o test test.c进行编译。编译错误是:

test.c: In function 'int main()':
test.c:20:42: error: no match for 'operator<<' in 'std::operator<< <std::char_traits<char> >((* & std::operator<< <char, std::char_traits<char>, std::allocator<char> >((* & std::cout), (* & v.std::pair<const std::basic_string<char>, boost::property_tree::basic_ptree<std::basic_string<char>, std::basic_string<char> > >::first))), ((const char*)":")) << v.std::pair<const std::basic_string<char>, boost::property_tree::basic_ptree<std::basic_string<char>, std::basic_string<char> > >::second'
test.c:20:42: note: candidates are:
In file included from /usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/istream:41:0,
                 from /usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/fstream:40,
                 from test.c:1:
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/ostream:106:7: note: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(std::basic_ostream<_CharT, _Traits>::__ostream_type& (*)(std::basic_ostream<_CharT, _Traits>::__ostream_type&)) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/ostream:106:7: note:   no known conversion for argument 1 from 'boost::property_tree::basic_ptree<std::basic_string<char>, std::basic_string<char> >' to 'std::basic_ostream<char>::__ostream_type& (*)(std::basic_ostream<char>::__ostream_type&) {aka std::basic_ostream<char>& (*)(std::basic_ostream<char>&)}'
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/ostream:115:7: note: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(std::basic_ostream<_CharT, _Traits>::__ios_type& (*)(std::basic_ostream<_CharT, _Traits>::__ios_type&)) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>; std::basic_ostream<_CharT, _Traits>::__ios_type = std::basic_ios<char>]
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/ostream:115:7: note:   no known conversion for argument 1 from 'boost::property_tree::basic_ptree<std::basic_string<char>, std::basic_string<char> >' to 'std::basic_ostream<char>::__ios_type& (*)(std::basic_ostream<char>::__ios_type&) {aka std::basic_ios<char>& (*)(std::basic_ios<char>&)}'
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/ostream:125:7: note: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(std::ios_base& (*)(std::ios_base&)) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/ostream:125:7: note:   no known conversion for argument 1 from 'boost::property_tree::basic_ptree<std::basic_string<char>, std::basic_string<char> >' to 'std::ios_base& (*)(std::ios_base&)'
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/ostream:164:7: note: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long int) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/ostream:164:7: note:   no known conversion for argument 1 from 'boost::property_tree::basic_ptree<std::basic_string<char>, std::basic_string<char> >' to 'long int'
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/ostream:168:7: note: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long unsigned int) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/ostream:168:7: note:   no known conversion for argument 1 from 'boost::property_tree::basic_ptree<std::basic_string<char>, std::basic_string<char> >' to 'long unsigned int'
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/ostream:172:7: note: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(bool) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/ostream:172:7: note:   no known conversion for argument 1 from 'boost::property_tree::basic_ptree<std::basic_string<char>, std::basic_string<char> >' to 'bool'
In file included from /usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/ostream:607:0,
                 from /usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/istream:41,
                 from /usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/fstream:40,
                 from test.c:1:
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/bits/ostream.tcc:93:5: note: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(short int) [with _CharT = char; _Traits = std::char_traits<char>]
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/bits/ostream.tcc:93:5: note:   no known conversion for argument 1 from 'boost::property_tree::basic_ptree<std::basic_string<char>, std::basic_string<char> >' to 'short int'
In file included from /usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/istream:41:0,
                 from /usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/fstream:40,
                 from test.c:1:
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/ostream:179:7: note: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(short unsigned int) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/ostream:179:7: note:   no known conversion for argument 1 from 'boost::property_tree::basic_ptree<std::basic_string<char>, std::basic_string<char> >' to 'short unsigned int'
In file included from /usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/ostream:607:0,
                 from /usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/istream:41,
                 from /usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/fstream:40,
                 from test.c:1:
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/bits/ostream.tcc:107:5: note: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(int) [with _CharT = char; _Traits = std::char_traits<char>]
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/bits/ostream.tcc:107:5: note:   no known conversion for argument 1 from 'boost::property_tree::basic_ptree<std::basic_string<char>, std::basic_string<char> >' to 'int'
In file included from /usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/istream:41:0,
                 from /usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/fstream:40,
                 from test.c:1:
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/ostream:190:7: note: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(unsigned int) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/ostream:190:7: note:   no known conversion for argument 1 from 'boost::property_tree::basic_ptree<std::basic_string<char>, std::basic_string<char> >' to 'unsigned int'
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/ostream:199:7: note: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long long int) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/ostream:199:7: note:   no known conversion for argument 1 from 'boost::property_tree::basic_ptree<std::basic_string<char>, std::basic_string<char> >' to 'long long int'
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/ostream:203:7: note: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long long unsigned int) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/ostream:203:7: note:   no known conversion for argument 1 from 'boost::property_tree::basic_ptree<std::basic_string<char>, std::basic_string<char> >' to 'long long unsigned int'
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/ostream:218:7: note: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(double) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/ostream:218:7: note:   no known conversion for argument 1 from 'boost::property_tree::basic_ptree<std::basic_string<char>, std::basic_string<char> >' to 'double'
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/ostream:222:7: note: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(float) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/ostream:222:7: note:   no known conversion for argument 1 from 'boost::property_tree::basic_ptree<std::basic_string<char>, std::basic_string<char> >' to 'float'
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/ostream:230:7: note: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long double) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/ostream:230:7: note:   no known conversion for argument 1 from 'boost::property_tree::basic_ptree<std::basic_string<char>, std::basic_string<char> >' to 'long double'
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/ostream:243:7: note: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(const void*) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/ostream:243:7: note:   no known conversion for argument 1 from 'boost::property_tree::basic_ptree<std::basic_string<char>, std::basic_string<char> >' to 'const void*'
In file included from /usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/ostream:607:0,
                 from /usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/istream:41,
                 from /usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/fstream:40,
                 from test.c:1:
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/bits/ostream.tcc:121:5: note: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(std::basic_ostream<_CharT, _Traits>::__streambuf_type*) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__streambuf_type = std::basic_streambuf<char>]
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/bits/ostream.tcc:121:5: note:   no known conversion for argument 1 from 'boost::property_tree::basic_ptree<std::basic_string<char>, std::basic_string<char> >' to 'std::basic_ostream<char>::__streambuf_type* {aka std::basic_streambuf<char>*}'
In file included from /usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/string:54:0,
                 from /usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/bits/locale_classes.h:42,
                 from /usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/bits/ios_base.h:43,
                 from /usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/ios:43,
                 from /usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/istream:40,
                 from /usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/fstream:40,
                 from test.c:1:
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/bits/basic_string.h:2750:5: note: template<class _CharT, class _Traits, class _Alloc> std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, const std::basic_string<_CharT, _Traits, _Alloc>&)
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/bits/basic_string.h:2750:5: note:   template argument deduction/substitution failed:
test.c:20:42: note:   'boost::property_tree::basic_ptree<std::basic_string<char>, std::basic_string<char> >' is not derived from 'const std::basic_string<_CharT, _Traits, _Alloc>'
In file included from /usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/istream:41:0,
                 from /usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/fstream:40,
                 from test.c:1:
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/ostream:469:5: note: template<class _CharT, class _Traits> std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, _CharT)
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/ostream:469:5: note:   template argument deduction/substitution failed:
test.c:20:42: note:   deduced conflicting types for parameter '_CharT' ('char' and 'boost::property_tree::basic_ptree<std::basic_string<char>, std::basic_string<char> >')
In file included from /usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/istream:41:0,
                 from /usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/fstream:40,
                 from test.c:1:
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/ostream:474:5: note: template<class _CharT, class _Traits> std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, char)
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/ostream:474:5: note:   template argument deduction/substitution failed:
test.c:20:42: note:   cannot convert 'v.std::pair<const std::basic_string<char>, boost::property_tree::basic_ptree<std::basic_string<char>, std::basic_string<char> > >::second' (type 'boost::property_tree::basic_ptree<std::basic_string<char>, std::basic_string<char> >') to type 'char'
In file included from /usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/istream:41:0,
                 from /usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/fstream:40,
                 from test.c:1:
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/ostream:480:5: note: template<class _Traits> std::basic_ostream<char, _Traits>& std::operator<<(std::basic_ostream<char, _Traits>&, char)
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/ostream:480:5: note:   template argument deduction/substitution failed:
test.c:20:42: note:   cannot convert 'v.std::pair<const std::basic_string<char>, boost::property_tree::basic_ptree<std::basic_string<char>, std::basic_string<char> > >::second' (type 'boost::property_tree::basic_ptree<std::basic_string<char>, std::basic_string<char> >') to type 'char'
In file included from /usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/istream:41:0,
                 from /usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/fstream:40,
                 from test.c:1:
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/ostream:486:5: note: template<class _Traits> std::basic_ostream<char, _Traits>& std::operator<<(std::basic_ostream<char, _Traits>&, signed char)
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/ostream:486:5: note:   template argument deduction/substitution failed:
test.c:20:42: note:   cannot convert 'v.std::pair<const std::basic_string<char>, boost::property_tree::basic_ptree<std::basic_string<char>, std::basic_string<char> > >::second' (type 'boost::property_tree::basic_ptree<std::basic_string<char>, std::basic_string<char> >') to type 'signed char'
In file included from /usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/istream:41:0,
                 from /usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/fstream:40,
                 from test.c:1:
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/ostream:491:5: note: template<class _Traits> std::basic_ostream<char, _Traits>& std::operator<<(std::basic_ostream<char, _Traits>&, unsigned char)
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/ostream:491:5: note:   template argument deduction/substitution failed:
test.c:20:42: note:   cannot convert 'v.std::pair<const std::basic_string<char>, boost::property_tree::basic_ptree<std::basic_string<char>, std::basic_string<char> > >::second' (type 'boost::property_tree::basic_ptree<std::basic_string<char>, std::basic_string<char> >') to type 'unsigned char'
In file included from /usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/istream:41:0,
                 from /usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/fstream:40,
                 from test.c:1:
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/ostream:511:5: note: template<class _CharT, class _Traits> std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, const _CharT*)
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/ostream:511:5: note:   template argument deduction/substitution failed:
test.c:20:42: note:   mismatched types 'const _CharT*' and 'boost::property_tree::basic_ptree<std::basic_string<char>, std::basic_string<char> >'
In file included from /usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/ostream:607:0,
                 from /usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/istream:41,
                 from /usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/fstream:40,
                 from test.c:1:
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/bits/ostream.tcc:323:5: note: template<class _CharT, class _Traits> std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, const char*)
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/bits/ostream.tcc:323:5: note:   template argument deduction/substitution failed:
test.c:20:42: note:   cannot convert 'v.std::pair<const std::basic_string<char>, boost::property_tree::basic_ptree<std::basic_string<char>, std::basic_string<char> > >::second' (type 'boost::property_tree::basic_ptree<std::basic_string<char>, std::basic_string<char> >') to type 'const char*'
In file included from /usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/istream:41:0,
                 from /usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/fstream:40,
                 from test.c:1:
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/ostream:528:5: note: template<class _Traits> std::basic_ostream<char, _Traits>& std::operator<<(std::basic_ostream<char, _Traits>&, const char*)
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/ostream:528:5: note:   template argument deduction/substitution failed:
test.c:20:42: note:   cannot convert 'v.std::pair<const std::basic_string<char>, boost::property_tree::basic_ptree<std::basic_string<char>, std::basic_string<char> > >::second' (type 'boost::property_tree::basic_ptree<std::basic_string<char>, std::basic_string<char> >') to type 'const char*'
In file included from /usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/istream:41:0,
                 from /usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/fstream:40,
                 from test.c:1:
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/ostream:541:5: note: template<class _Traits> std::basic_ostream<char, _Traits>& std::operator<<(std::basic_ostream<char, _Traits>&, const signed char*)
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/ostream:541:5: note:   template argument deduction/substitution failed:
test.c:20:42: note:   cannot convert 'v.std::pair<const std::basic_string<char>, boost::property_tree::basic_ptree<std::basic_string<char>, std::basic_string<char> > >::second' (type 'boost::property_tree::basic_ptree<std::basic_string<char>, std::basic_string<char> >') to type 'const signed char*'
In file included from /usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/istream:41:0,
                 from /usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/fstream:40,
                 from test.c:1:
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/ostream:546:5: note: template<class _Traits> std::basic_ostream<char, _Traits>& std::operator<<(std::basic_ostream<char, _Traits>&, const unsigned char*)
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/ostream:546:5: note:   template argument deduction/substitution failed:
test.c:20:42: note:   cannot convert 'v.std::pair<const std::basic_string<char>, boost::property_tree::basic_ptree<std::basic_string<char>, std::basic_string<char> > >::second' (type 'boost::property_tree::basic_ptree<std::basic_string<char>, std::basic_string<char> >') to type 'const unsigned char*'
In file included from /usr/include/boost/spirit/home/classic/utility/impl/chset/basic_chset.hpp:13:0,
                 from /usr/include/boost/spirit/home/classic/utility/chset.hpp:16,
                 from /usr/include/boost/spirit/home/classic/utility.hpp:26,
                 from /usr/include/boost/spirit/home/classic.hpp:29,
                 from /usr/include/boost/spirit/include/classic.hpp:11,
                 from /usr/include/boost/property_tree/detail/json_parser_read.hpp:18,
                 from /usr/include/boost/property_tree/json_parser.hpp:14,
                 from test.c:3:
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/bitset:1523:5: note: template<class _CharT, class _Traits, long unsigned int _Nb> std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, const std::bitset<_Nb>&)
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/bitset:1523:5: note:   template argument deduction/substitution failed:
test.c:20:42: note:   'boost::property_tree::basic_ptree<std::basic_string<char>, std::basic_string<char> >' is not derived from 'const std::bitset<_Nb>'
In file included from /usr/include/boost/property_tree/detail/json_parser_write.hpp:18:0,
                 from /usr/include/boost/property_tree/json_parser.hpp:15,
                 from test.c:3:
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/iomanip:78:5: note: template<class _CharT, class _Traits> std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, std::_Resetiosflags)
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/iomanip:78:5: note:   template argument deduction/substitution failed:
test.c:20:42: note:   cannot convert 'v.std::pair<const std::basic_string<char>, boost::property_tree::basic_ptree<std::basic_string<char>, std::basic_string<char> > >::second' (type 'boost::property_tree::basic_ptree<std::basic_string<char>, std::basic_string<char> >') to type 'std::_Resetiosflags'
In file included from /usr/include/boost/property_tree/detail/json_parser_write.hpp:18:0,
                 from /usr/include/boost/property_tree/json_parser.hpp:15,
                 from test.c:3:
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/iomanip:108:5: note: template<class _CharT, class _Traits> std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, std::_Setiosflags)
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/iomanip:108:5: note:   template argument deduction/substitution failed:
test.c:20:42: note:   cannot convert 'v.std::pair<const std::basic_string<char>, boost::property_tree::basic_ptree<std::basic_string<char>, std::basic_string<char> > >::second' (type 'boost::property_tree::basic_ptree<std::basic_string<char>, std::basic_string<char> >') to type 'std::_Setiosflags'
In file included from /usr/include/boost/property_tree/detail/json_parser_write.hpp:18:0,
                 from /usr/include/boost/property_tree/json_parser.hpp:15,
                 from test.c:3:
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/iomanip:142:5: note: template<class _CharT, class _Traits> std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, std::_Setbase)
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/iomanip:142:5: note:   template argument deduction/substitution failed:
test.c:20:42: note:   cannot convert 'v.std::pair<const std::basic_string<char>, boost::property_tree::basic_ptree<std::basic_string<char>, std::basic_string<char> > >::second' (type 'boost::property_tree::basic_ptree<std::basic_string<char>, std::basic_string<char> >') to type 'std::_Setbase'
In file included from /usr/include/boost/property_tree/detail/json_parser_write.hpp:18:0,
                 from /usr/include/boost/property_tree/json_parser.hpp:15,
                 from test.c:3:
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/iomanip:177:5: note: template<class _CharT, class _Traits> std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, std::_Setfill<_CharT>)
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/iomanip:177:5: note:   template argument deduction/substitution failed:
test.c:20:42: note:   'boost::property_tree::basic_ptree<std::basic_string<char>, std::basic_string<char> >' is not derived from 'std::_Setfill<_CharT>'
In file included from /usr/include/boost/property_tree/detail/json_parser_write.hpp:18:0,
                 from /usr/include/boost/property_tree/json_parser.hpp:15,
                 from test.c:3:
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/iomanip:207:5: note: template<class _CharT, class _Traits> std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, std::_Setprecision)
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/iomanip:207:5: note:   template argument deduction/substitution failed:
test.c:20:42: note:   cannot convert 'v.std::pair<const std::basic_string<char>, boost::property_tree::basic_ptree<std::basic_string<char>, std::basic_string<char> > >::second' (type 'boost::property_tree::basic_ptree<std::basic_string<char>, std::basic_string<char> >') to type 'std::_Setprecision'
In file included from /usr/include/boost/property_tree/detail/json_parser_write.hpp:18:0,
                 from /usr/include/boost/property_tree/json_parser.hpp:15,
                 from test.c:3:
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/iomanip:237:5: note: template<class _CharT, class _Traits> std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, std::_Setw)
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/iomanip:237:5: note:   template argument deduction/substitution failed:
test.c:20:42: note:   cannot convert 'v.std::pair<const std::basic_string<char>, boost::property_tree::basic_ptree<std::basic_string<char>, std::basic_string<char> > >::second' (type 'boost::property_tree::basic_ptree<std::basic_string<char>, std::basic_string<char> >') to type 'std::_Setw'

1 个答案:

答案 0 :(得分:0)

我将我的文件命名为test.c而不是test.cpp,这可能是一个问题。但改变这一点并没有解决问题。我将v.second更改为v.second.data(),但效果很好。