c++ - Matching strings using Boost Spirit -


i learning boost spirit , modified example given in documentation match strings instead of doubles. code doesn't compile , errors unable debug. below code , printed errors. can please me debug problem ?

ps: guessing problem lies in using phoenix::ref vector string, not sure how , why.

#include <boost/spirit/include/qi.hpp> #include <boost/spirit/include/phoenix_core.hpp> #include <boost/spirit/include/phoenix_operator.hpp> #include <boost/spirit/include/phoenix_stl.hpp> #include <boost/config/warning_disable.hpp>  #include <iostream> #include <string> #include <vector>  namespace client {     namespace qi = boost::spirit::qi;     namespace ascii = boost::spirit::ascii;     namespace phoenix = boost::phoenix;      template <typename iterator>      bool parse_data(iterator first, iterator last, std::vector<std::string>& v)     {         using qi::double_;         using qi::char_;         using qi::phrase_parse;         using qi::_1;         using ascii::space;         using phoenix::ref;         using phoenix::push_back;          bool r = phrase_parse(             first,             last,             +(char_)[push_back(ref(v), _1)],                     char_('/')           );         if (first != last)             return false;         return r;     } }  int  main() {     std::string str;      while (getline(std::cin, str))     {         if (str.empty())             break;          std::vector<std::string> v;         if(client::parse_data(str.begin(), str.end(), v))         {             std::cout << std::endl << "parsing done" << std::endl;             std::cout << "numbers " ;             for(std::vector<std::string>::iterator = v.begin(); < v.end(); i++)             {                 std::cout << *i <<" ";             }             std::cout << std::endl;         }         else         {             std::cout << "parsing failed" << std::endl;         }     }      return 0; } 

this error get:

/usr/local/include/boost_1_46_1/boost/spirit/home/phoenix/stl/container/container.hpp:492: error: invalid conversion ‘const char’ ‘const char*’  /usr/local/include/boost_1_46_1/boost/spirit/home/phoenix/stl/container/container.hpp:492:  error:   initializing argument 1 of ‘std::basic_string<_chart, _traits, _alloc>::basic_string(const _chart*, const _alloc&) [with _chart = char, _traits = std::char_traits<char>, _alloc = std::allocator<char>]’ 

if write

bool r = phrase_parse(     first, last, +(char_[push_back(ref(v), _1)]), char_('/')   ); 

it work. writing

bool r = phrase_parse(     first, last, +char_, '/', v ); 

is simpler (and runs faster).


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -