#include <iostream>
#include <boost/spirit/include/qi.hpp>
namespace qi = boost::spirit::qi;
int main ()
{
// the following parses "1.0 2.0" into a pair of double
std::string input("1.0 2.0");
std::string::iterator strbegin = input.begin();
std::pair<double, double> p;
qi::phrase_parse(strbegin, input.end(),
qi::double_ >> qi::double_, // parser grammar
qi::space, // delimiter grammar
p); // attribute to fill while parsing
}
的示例
我收到编译错误
main.cpp:14:14: instantiated from here
/usr/local/include/boost/spirit/home/qi/detail/assign_to.hpp:152:13: error: no matching function for call to ‘std::pair<double, double>::pair(const double&)’
/usr/local/include/boost/spirit/home/qi/detail/assign_to.hpp:152:13: note: candidates are:
/usr/include/c++/4.6/bits/stl_pair.h:108:21: note: template<class _U1, class _U2> std::pair::pair(const std::pair<_U1, _U2>&)
/usr/include/c++/4.6/bits/stl_pair.h:103:26: note: std::pair<_T1, _T2>::pair(const _T1&, const _T2&) [with _T1 = double, _T2 = double]
/usr/include/c++/4.6/bits/stl_pair.h:103:26: note: candidate expects 2 arguments, 1 provided
/usr/include/c++/4.6/bits/stl_pair.h:99:26: note: std::pair<_T1, _T2>::pair() [with _T1 = double, _T2 = double]
/usr/include/c++/4.6/bits/stl_pair.h:99:26: note: candidate expects 0 arguments, 1 provided
/usr/include/c++/4.6/bits/stl_pair.h:87:12: note: std::pair<double, double>::pair(const std::pair<double, double>&)
/usr/include/c++/4.6/bits/stl_pair.h:87:12: note: no known conversion for argument 1 from ‘const double’ to ‘const std::pair<double, double>&’
make: *** [all] Error 1
答案 0 :(得分:8)
您需要将该对调整为融合序列,这可以通过包含
来完成#include <boost/fusion/adapted/std_pair.hpp>