Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <boost/config/warning_disable.hpp>
- #include <boost/spirit/include/qi.hpp>
- #include <iostream>
- #include <string>
- namespace qi = boost::spirit::qi;
- namespace ascii = boost::spirit::ascii;
- void onDouble(const double& d) {
- std::cout << "Found: " << d << std::endl;
- }
- template <typename Iterator>
- bool parse_numbers(Iterator first, Iterator last) {
- using qi::double_;
- using qi::phrase_parse;
- using ascii::space;
- bool r = phrase_parse(
- first,
- last,
- double_[&onDouble] >> *(',' >> double_[&onDouble]),
- space
- );
- if (first != last) {
- return false;
- }
- return r;
- }
- int main() {
- std::string data("21.2, 34,5, 58.4, 56");
- if (parse_numbers(data.begin(), data.end())) {
- std::cout << "It works" << std::endl;
- } else {
- std::cout << "It failed" << std::endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement