fork download
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. int main(){
  5.  
  6. std::vector <int> vector1;
  7. std::vector <int> vector2;
  8.  
  9. // int vector1_1addition; Note: These lines are unnecessary
  10. // int vector1_2addition;
  11. //
  12. // std::cin >> vector1_1addition; //add 10
  13. // std::cin >> vector1_2addition; //add 20
  14.  
  15. vector1.push_back (10);
  16. vector1.push_back (20);
  17.  
  18. std::cout << "The numbers in vector 1 are: " << vector1.at(0) <<" " << vector1.at(1) <<std::endl;
  19. std::cout << "The size of the vector 1 is: " << vector1.size() << std::endl;
  20.  
  21. // int vector2_1addition; Note: These lines are unnecessary
  22. // int vector2_2addition;
  23. //
  24. // std::cin >> vector2_1addition; //add 100
  25. // std::cin >> vector2_2addition; //add 200
  26.  
  27. vector2.push_back (100);
  28. vector2.push_back (200);
  29.  
  30. std::cout << "The numbers in vector 2 are: " << vector2.at(0) << " " << vector2.at(1) <<std::endl;
  31. std::cout << "The size of vector 2 is: " << vector2.size() << std::endl;
  32.  
  33. std::vector <std::vector <int> > vector_2d;
  34.  
  35. vector_2d.push_back(vector1);
  36. vector_2d.push_back(vector2);
  37.  
  38. std::cout << " The 1st row elements in the 2 dimensional vector are: " << vector_2d.at(0).at(0) << " " << vector_2d.at(1).at(0) << std::endl;
  39. std::cout << " The 1st row elements in the 2 dimensional vector are: " << vector_2d.at(0).at(1) << " " << vector_2d.at(1).at(1) << std::endl;
  40.  
  41. vector1.at(0) = 1000;
  42.  
  43. std::cout << " The new elements in row 1 of the 2 dimensional vector are: " << vector_2d.at(0).at(0) << " " << vector_2d.at(1).at(0) << std::endl;
  44. std::cout << " The new elements in row 2 of the 2 dimensional vector are: " << vector_2d.at(0).at(1) << " " << vector_2d.at(1).at(1) << std::endl;
  45.  
  46. std::cout << " The new elements in vector 1 are: " << vector1.at(0) << " " << vector1.at(1) << std::endl;
  47.  
  48. system("pause");
  49.  
  50.  
  51. return 0;
  52. }
Success #stdin #stdout #stderr 0s 15240KB
stdin
Standard input is empty
stdout
The numbers in vector 1 are: 10 20
The size of the vector 1 is: 2
The numbers in vector 2 are: 100 200
The size of vector 2 is: 2
 The 1st row elements in the 2 dimensional vector are: 10 100
 The 1st row elements in the 2 dimensional vector are: 20 200
 The new elements in row 1 of the 2 dimensional vector are: 10 100
 The new elements in row 2 of the 2 dimensional vector are: 20 200
 The new elements in vector 1 are: 1000 20
stderr
sh: 1: pause: not found