Opened 11 years ago
Closed 5 years ago
#6750 closed Bugs (fixed)
istream_iterator in spirit might have defect
Reported by: | Owned by: | Joel de Guzman | |
---|---|---|---|
Milestone: | To Be Determined | Component: | spirit |
Version: | Boost 1.49.0 | Severity: | Problem |
Keywords: | istream_iterator | Cc: |
Description
The following program yields a wrong parsing result:
#include <iostream> #include <vector> #include <algorithm> #include <iterator> #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> namespace spirit = boost::spirit ; namespace qi = boost::spirit::qi ; namespace ascii = boost::spirit::ascii ; namespace phoenix = boost::phoenix ; using qi::double_ ; using qi::_1 ; using phoenix::push_back ; using phoenix::ref ; int main (int argc, char* argv[]) { spirit::istream_iterator iter (std::cin), end ; std::vector<double> v ; bool r = spirit::qi::phrase_parse (iter, end, double_ [push_back (ref(v), _1)] % ',', ascii::space) ; if (r) { std::cout << "vector: " ; std::copy (v.begin(), v.end(), std::ostream_iterator<double> (std::cout, ", ")) ; std::cout << std::endl ; } return 0 ; }
You may test it with input like "1,2,3,4" and the output is "vector: 1,2,3,44,". When we switch to std::getline and use the std::string::const_iterator, the result turns out fine.
Change History (2)
comment:1 by , 5 years ago
comment:2 by , 5 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Note:
See TracTickets
for help on using tickets.
Cannot reproduce, it prints
vector: 1, 2, 3, 4,
for me.