fork download
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <vector>
  4. using namespace std;
  5.  
  6. void Show(vector<int> &v)
  7. {
  8. vector<int> :: iterator it = v.begin();
  9. while (it != v.end())
  10. {
  11. cout<<*it<<" ";
  12. it++;
  13. }
  14. cout<<endl;
  15.  
  16. }
  17.  
  18.  
  19. int main()
  20. {
  21. vector<int> v1,v2;
  22. for (int i=0;i<10;i++) v1.push_back(i);
  23. for (int i=0;i<5;i++) v2.push_back(i+10);
  24. vector<int>().swap(v1);
  25. Show(v1);
  26. Show(v2);
  27. cout<<v1.size()<<" "<<v1.capacity()<<endl;
  28. cout<<v2.size()<<" "<<v2.capacity()<<endl;
  29.  
  30.  
  31. }
Success #stdin #stdout 0s 3464KB
stdin
Standard input is empty
stdout
10 11 12 13 14 
0 0
5 8