6

istreamx3を使用してから解析する正しい方法を見つけようとしています。古いドキュメントは何かを参照してmulti_passいますが、これを引き続き使用できますか? または、バックトラックできるように X3 のストリームをバッファリングする他の方法はありますか?

4

1 に答える 1

7

これならまだ使えます。含めるだけ

#include <boost/spirit/include/support_istream_iterator.hpp>

Live On Coliru

#include <boost/spirit/home/x3.hpp>
#include <boost/spirit/include/support_istream_iterator.hpp>
#include <iostream>
#include <sstream>

int main() {
    std::istringstream iss("{ 123, 234, 345, 456, 567, 678, 789, 900, 1011 }");
    boost::spirit::istream_iterator f(iss), l;

    std::vector<int> values;

    namespace x3 = boost::spirit::x3;

    if (x3::phrase_parse(f, l, '{' >> (x3::int_ % ',') >> '}', x3::space, values)) {
        std::cout << "Parse results:\n";
        for (auto v : values) std::cout << v << " ";
    } else
        std::cout << "Parse failed\n";
}

版画

Parse results:
123 234 345 456 567 678 789 900 1011 
于 2016-05-06T20:36:09.773 に答える