parsing - How to use boost.spirit.qi parse string value to attrubute with attribute has default value -


i have question boost.spirit.qi string parser. when want parse string value std::string attribute, bellow:

#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; } 

the output:abccba

but want program output "cba", how can do?

note str initialized "abc". parser not clear string, appends output. pass in empty string , want.


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -