fork download
  1. #include <vector>
  2. #include <iostream>
  3.  
  4. using namespace std;
  5.  
  6. int main ()
  7. {
  8. vector<vector<int> > vec2D;
  9.  
  10. cout << "i-capacity before reserve: " << vec2D.capacity() << endl;
  11. vec2D.reserve(5);
  12. cout << "i-capacity after reserve: " << vec2D.capacity() << endl << endl;
  13.  
  14. for (int i=0; i<5; i++) {
  15. cout << "i = " << i << endl;
  16. cout << "j-capacity before reserve: " << vec2D[i].capacity() << endl;
  17. vec2D[i].reserve(3);
  18. cout << "j-capacity after reserve: " << vec2D[i].capacity() << endl;
  19. for (int j=0; j<3; j++) {
  20. vec2D[i][j] = i*5 + j;
  21. }
  22. }
  23.  
  24. return 0;
  25. }
Success #stdin #stdout 0s 3476KB
stdin
Standard input is empty
stdout
i-capacity before reserve: 0
i-capacity after reserve: 5

i = 0
j-capacity before reserve: 0
j-capacity after reserve: 3
i = 1
j-capacity before reserve: 0
j-capacity after reserve: 3
i = 2
j-capacity before reserve: 0
j-capacity after reserve: 3
i = 3
j-capacity before reserve: 0
j-capacity after reserve: 3
i = 4
j-capacity before reserve: 0
j-capacity after reserve: 3