fork(9) download
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. int main() {
  5. // Vector of vectors
  6. std::vector<std::vector<int>> matrix;
  7. for(int i=0;i<3;++i) {
  8. //Create a vector
  9. std::vector<int> row;
  10. for(int j=0;j<3;++j){
  11. int value;
  12. std::cin >> value;
  13. row.push_back(value);
  14. }
  15. //Push the row in matrix
  16. matrix.push_back(row);
  17. }
  18. std::cout << "Vector contents are: \n";
  19. for(int i=0;i<3;++i) {
  20. for(int j=0;j<3;++j){
  21. std::cout << matrix[i][j] << " ";
  22. }
  23. std::cout << "\n";
  24. }
  25. return 0;
  26. }
Success #stdin #stdout 0s 3476KB
stdin
1 2 3
4 5 6
7 8 9
stdout
Vector contents are: 
1 2 3 
4 5 6 
7 8 9