fork(1) download
  1. #include <iostream>
  2. #include <vector>
  3. int main()
  4. {
  5. std::vector< std::vector<int> > array =
  6. {{1, 0, 0, 1},
  7. {1, 0, 1},
  8. {2, 1},
  9. {1, 3, 4}};
  10.  
  11. // can add rows whenever
  12. std::vector<int> row = {1,2,3,4,5};
  13. array.push_back(row);
  14.  
  15. // can resize existing rows, too
  16. array[0].resize(6);
  17.  
  18. // print:
  19. for(auto& row: array) {
  20. for(int n: row)
  21. std::cout << n << ' ';
  22. std::cout << '\n';
  23. }
  24. }
  25.  
Success #stdin #stdout 0s 2988KB
stdin
Standard input is empty
stdout
1 0 0 1 0 0 
1 0 1 
2 1 
1 3 4 
1 2 3 4 5