Advertisement
mario_mos

vectors1

Sep 1st, 2023 (edited)
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.57 KB | None | 0 0
  1. #include <iostream>
  2. #include<vector>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.    vector<int> a(5,10);
  9.    a.push_back(4);
  10.    a.push_back(0);
  11.    int nb=a.size();
  12.    int size=a.capacity();
  13.  
  14.    cout << "nb a = " << nb << " size a = " << size << endl;
  15.     vector<int> myvector;
  16.     for (int i=1; i<=5; i++) myvector.push_back(i);
  17.     for (vector<int>::iterator it = myvector.begin() ;    it != myvector.end(); ++it)
  18.     cout << ' ' << *it;
  19.     cout << endl;
  20.  
  21.     for (auto i : myvector)
  22.     {
  23.         cout << i << ' ';
  24.         cout << endl;
  25.  
  26.     }
  27.  
  28.     return 0;
  29. }
  30.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement