2016-05-06 9 views
3

x3を使用してistreamから解析する正しい方法を見つけようとしています。以前のドキュメントではmulti_passのものを参照していますが、これはまだ使用できますか?または、X3のストリームをバッファリングして戻すことができる他の方法がありますか?Boost Spirit X3で "ストリーム"解析を行うには?

答えて

4

これは引き続き使用できます。ただ、

#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 
が含まれます
関連する問題