fork download
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8. vector <int> vec(10);
  9. for(int i=0; i<10; i++){
  10. vec[i]=i+1;
  11. cout << vec[i] << endl;
  12. }
  13. cout << "the length of this vector is " << vec.size() << endl;
  14. vec.resize(20);
  15. for(int i=0; i<20; i++){
  16. vec[i]=i+1;
  17. cout << vec[i] << endl;
  18. }
  19. cout << "the length of this vector is " << vec.size() << endl;
  20. }
Success #stdin #stdout 0s 3428KB
stdin
Standard input is empty
stdout
1
2
3
4
5
6
7
8
9
10
the length of this vector is 10
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
the length of this vector is 20