-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSTL_vectors.cpp
More file actions
31 lines (31 loc) · 824 Bytes
/
STL_vectors.cpp
File metadata and controls
31 lines (31 loc) · 824 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include<iostream>
#include<vector>
using namespace std;
template <class T>
void display(vector<T> &v){
for (int i = 0; i < v.size(); i++)
{
cout<<v[i]<<" ";
}
cout<<endl;
}
int main(){
vector<int> vec1;
int element, size;
cout<<"Enter the size of your vector"<<endl;
cin>>size;
for (int i = 0; i < size; i++)
{
cout<<"Enter an element to add to this vector: ";
cin>>element;
vec1.push_back(element);
}
display(vec1);
vec1.pop_back(); //remove one element from back
display(vec1);
vector<int> :: iterator iter = vec1.begin();
vec1.insert(iter,6,5); //here 6 represents the number of times you want to add 5
//for inserting at 2nd position, write iter+1
display(vec1);
return 0;
}