C++ regex parsing numbers out of string -


i trying extract numbers string in same row format. following code extracts numbers, not record last row of 4s. how should change regex repeated row of numbers?

    #include <iostream> #include <vector> #include <string> #include <regex> using namespace std;  const string data  ="4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4," "4,8,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,7,8,3,3,3,3,3,3,7,8,3,3,3,3,3,3,7,4," "4,6,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,5,6,1,1,1,1,1,1,5,6,1,1,1,1,1,1,5,4," "4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4"; int main() {     regex e("[1-9]");     sregex_token_iterator rit(data.begin(), data.end(), e);     sregex_token_iterator rend;     int = 0;     std::vector<std::vector<int>> double_array;     double_array.reserve(4);     std::vector<int> row;     row.reserve(40);     while(rit != rend)     {         if( ==  40)         {             double_array.push_back(row);             row.clear();             row.reserve(40);             = 0;         }         row.push_back(stoi(rit->str()));         ++i;         ++rit;     }      for(auto & disp_row : double_array)     {         for(auto & c : disp_row)         {             cout<< c << " ";         }         cout << "\n";     }     return 0; } 

(i haven't counted numbers; assuming say.)

when loop finishes, have processed 40 numbers in last block , sitting in row. if there 1 more item in list, before processing contents of row put double_array. there isn't, aren't.

you fix doing "do have 40 items yet? if so, put them in double_array" test after each item processed rather before.


Comments

Popular posts from this blog

javascript - How to get current YouTube IDs via iMacros? -

c# - Maintaining a program folder in program files out of date? -

emulation - Android map show my location didn't work -