Boost精神char解析器 [英] Boost Spirit char parser

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

问题描述

这里是一个代码示例:

  //文件main.cpp 

#include< ; iostream>
#include< boost / tuple / tuple.hpp>
#include< boost / tuple / tuple_io.hpp>
#include< boost / spirit / include / qi.hpp>

int main()
{
std :: string s(1 A);
boost :: tuple< double,char> p;
complex_matrix_parser :: iterator b = s.begin();
complex_matrix_parser :: iterator e = s.end();
qi :: phrase_parse(b,e,
(qi :: double_> qi :: char _('A')),
qi :: space,qi :: skip_flag :: postskip,p);

std :: cerr<< ====<< p < std :: endl;

return 0;
}

这应该打印 ==== )对不对?但它打印 ====(1),所以它跳过'A'字符。

解决方案

使用

boost :: fusion :: vector 而不是 boost :: tuple ,一切都会奏效。


Here is a code sample:

// file main.cpp

#include <iostream>
#include <boost/tuple/tuple.hpp>
#include <boost/tuple/tuple_io.hpp>
#include <boost/spirit/include/qi.hpp>

int main()
{
    std::string s( "1 A" );
    boost::tuple<double, char> p;
    complex_matrix_parser::iterator b = s.begin();
    complex_matrix_parser::iterator e = s.end();
    qi::phrase_parse( b, e,
            ( qi::double_ >> qi::char_('A') ),
            qi::space, qi::skip_flag::postskip, p );

    std::cerr << "==== " << p << std::endl;

    return 0;
}

This should print ==== (1 A) right? But it prints ==== (1 ), so it skips the 'A' character.

What am I doing wrong here?

解决方案

Use boost::fusion::vector instead of the boost::tuple and everything will work.

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

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