解析错误示例 [英] Example parsing error

查看:51
本文介绍了解析错误示例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正尝试在该示例之后解析一个示例,其中包含增强精神(2.5.2).我的代码如下

I'm trying to parse an example of boost spirit (2.5.2) following the example. My code is the following

#include <boost\spirit\home\qi.hpp>
#include <iostream>
#include <string>
#include <utility>

int main()
{

  // Parsing two numbers
  std::string input("1.0 2.0");
  std::pair<double, double> p;

  boost::spirit::qi::phrase_parse(
    input.begin(),
    input.end(),
    boost::spirit::qi::double_ >> boost::spirit::qi::double_ , // Parse grammar
    boost::spirit::qi::space,
    p
  );

  return 0;
}

这几乎等于找到的示例此处,但是当我使用Visual Studio 2010(32位,调试)进行编译时,出现以下错误:

It's almost equal to the example found here, but when I compile it with Visual studio 2010 (32 bit, debug) I obtain the following error:

error C2440: 'static_cast': unable to convert from 'const double' to 'std::pair<_Ty1,_Ty2>'

(错误可能略有不同,我已将其翻译为意大利语)

(the error can be slighty different, I've translated it from italian)

我在做错什么,如何成功编译示例?

What I'm doing wrong and how can I compile successfully the example?

预先感谢您的答复.

推荐答案

您缺少一个包含项:

#include <boost/fusion/adapted/std_pair.hpp>

它定义了属性分配规则,以使Fusion序列(vector2<>)可以分配给std :: pair.

It defines the attribute assignment rules to make Fusion sequences (vector2<>) assignable to std::pair.

实时查看代码: liveworkspace.org

See the code live: liveworkspace.org

#include <boost/spirit/include/qi.hpp>
#include <boost/fusion/adapted/std_pair.hpp>
#include <iostream>
#include <string>
#include <utility>

int main()
{
    // Parsing two numbers
    std::string input("1.2 3.4");
    std::pair<double, double> p;

    namespace qi = boost::spirit::qi;

    qi::phrase_parse(
            input.begin(), 
            input.end(),
            qi::double_ >> qi::double_ , // Parse grammar
            qi::space, p);

    std::cout << "Lo:     " << p.first << "\n"
              << "Behold: " << p.second << "\n";
}

这篇关于解析错误示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆