CPP   92
Size and Resize (vector C++)
Guest on 5th September 2023 01:02:05 AM


  1. #include<bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. void dump(vector <int>& vt)
  6. {
  7.     for(auto x:vt)
  8.         cout << x << " ";
  9.     cout << endl;
  10. }
  11. int main()
  12. {
  13.     vector <int> a{1,2,3};
  14.     cout << "Size before: " << a.size() << endl;
  15.  
  16.     int n;
  17.     cin >> n;
  18.    
  19.     a.resize(n);
  20.     dump(a);
  21.     cout << "Size after: " << a.size() << endl;
  22.  
  23.     return 0;
  24. }

Raw Paste

Login or Register to edit or fork this paste. It's free.