fork download
  1. #include <iostream>
  2. #include <iterator>
  3. #include <numeric>
  4. #include <string>
  5. #include <vector>
  6.  
  7. using namespace std;
  8.  
  9. int main() {
  10. const auto test = "1010eefabbccde1f1f"s;
  11. const vector<size_t> sizes { 4U, 4U, 6U, 4U };
  12. const auto result = accumulate(cbegin(sizes), cend(sizes), vector<int>(), [&, pos = 0U](auto& a, const auto& b) mutable {
  13. a.push_back(stoi(test.substr(pos, b), nullptr, 16));
  14. pos += b;
  15. return a;
  16. });
  17.  
  18. for(const auto& i : result) cout << i << endl;
  19. }
Success #stdin #stdout 0s 16064KB
stdin
Standard input is empty
stdout
4112
61178
12307678
7967