fork download
  1.  
  2. #include <iostream>
  3. #include <string>
  4. #include <vector>
  5.  
  6. #include <boost/spirit/include/qi.hpp>
  7. #include <boost/spirit/include/qi_parse.hpp>
  8. #include <boost/fusion/adapted/struct/adapt_struct.hpp>
  9.  
  10. class TEST
  11. {
  12. public:
  13. int x;
  14. int y;
  15. int z;
  16. };
  17.  
  18. BOOST_FUSION_ADAPT_STRUCT(TEST, (int, x)(int, y)(int, z))
  19.  
  20. int main(int argc, char ** argv)
  21. {
  22. using namespace std;
  23. namespace q = boost::spirit::qi;
  24.  
  25. string text = "val = [111,222,1][333,444,2][555,666,3] [ 777, 888 , -4]\n";
  26.  
  27. vector<TEST> testvec;
  28. q::phrase_parse(text.begin(), text.end()
  29. , q::lit("val") >> "=" >> +('[' >> q::int_ >> ',' >> q::int_ >> ',' >> q::int_ >> ']')
  30. , q::ascii::space, testvec);
  31.  
  32. for (int i(0), l(testvec.size()); i < l; ++i) {
  33. cout << i << " : " << testvec[i].x << "," << testvec[i].y << "," << testvec[i].z << endl;
  34. }
  35. return 0;
  36. }
  37.  
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty