aytdev

vector code

Apr 26th, 2021 (edited)
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. //C201050
  2. //AYAT ULLAH
  3. #include <bits/stdc++.h>
  4. using namespace std;
  5. int main()
  6. {
  7. vector<int> vec;
  8. int n,num;
  9. cout<<"Enter the vector size: "<<endl;
  10. cin>>n;
  11. for(int i=0;i<n;i++){
  12.  
  13. cin>>num;
  14. vec.push_back(num);
  15. }
  16. for(auto x: vec) cout<<x<<" ";
  17. cout<<endl;
  18. vector<int>::iterator it;
  19.  
  20. cout<<"Enter the position you want to erase: ";
  21. cin>>n;
  22.  
  23. vec.erase(vec.begin()+n);
  24. cout<<"Enter the new number you want to insert :";
  25. cin>>num;
  26. vec.insert(vec.begin()+n,num);
  27. cout<<"New vector"<<endl;
  28. for(auto x: vec) cout<<x<<" ";
  29. return 0;
  30. }
  31.  
Add Comment
Please, Sign In to add comment