You are asking Spirit to emit the spaces with qi::lexeme
. Compare: http://www.boost.org/doc/libs/1_55_0/libs/spirit/doc/html/spirit/qi/reference/directive/lexeme.html
The rule +(qi::char_ - qi::space)
should do.
Question
#include <iostream>
#include <boost/spirit/include/qi.hpp>
namespace qi = boost::spirit::qi;
int main ()
{
std::string input(" aaa ");
std::string::iterator strbegin = input.begin();
std::string p;
qi::phrase_parse(strbegin, input.end(),
qi::lexeme[+qi::char_],
qi::space,
p);
std::cout << p << std::endl;
std::cout << p.size() << std::endl;
}
In this code parser assigns "aaa "
to p
. Why doesn't it skip all spaces? I expect p
to be "aaa"
. How it can be fixed?
Solution
You are asking Spirit to emit the spaces with qi::lexeme
. Compare: http://www.boost.org/doc/libs/1_55_0/libs/spirit/doc/html/spirit/qi/reference/directive/lexeme.html
The rule +(qi::char_ - qi::space)
should do.