我对 boost.spirit.qi 字符串解析器有疑问。当我想将字符串值解析为 std::string 属性时,如下所示:
#include <boost/spirit/include/support_utree.hpp>
#include <boost/spirit/include/qi.hpp>
#include <boost/spirit/include/phoenix.hpp>
#include <boost/fusion/include/adapt_struct.hpp>
#include <boost/assert.hpp>
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
template <typename P, typename T>
void test_phrase_parser_attr(
char const* input, P const& p, T& attr, bool full_match = true)
{
using boost::spirit::qi::phrase_parse;
using boost::spirit::qi::ascii::space;
char const* f(input);
char const* l(f + strlen(f));
if (phrase_parse(f, l, p, space, attr) && (!full_match || (f == l)))
std::cout << "ok" << std::endl;
else
std::cout << "fail" << std::endl;
}
int main()
{
std::string str("abc");
test_phrase_parser_attr("cba", string("cba"), str);
std::cout << str << std::endl;
return 0;
}
输出:abccba
但是我想要程序输出“cba”,我该怎么办?