forked from KaushikiKrity/hello_C_language
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvector.cpp
38 lines (28 loc) · 820 Bytes
/
vector.cpp
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
32
33
34
35
36
37
38
#include<iostream>
#include<vector>
using namespace std;
int main()
{
vector<string> v;
cout<<"Initial Capacity = "<<v.capacity()<<endl;
//Pushing elements in the vector
v.push_back("Raju");
v.push_back("Ravi");
v.push_back("Jay");
v.push_back("Sunil");
vector<string>::iterator i=v.begin();
//Element inserted at 2nd position in the vector
v.insert(i+1,"Mohan");
cout<<"--------------"<<endl;
cout<<"First element in the vector:";
cout<<v.front()<<endl;
cout<<"Last element in the vector:";
cout<<v.back()<<endl;
cout<<"--------------"<<endl;
cout<<"Elements present in the vector:"<<endl;
for(int i=0;i<v.size();i++)
cout<<v[i]<<endl;
cout<<"--------------"<<endl;
cout<<"Final Capacity = "<<v.capacity()<<endl;
return 0;
}