-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvectorClass.cpp
More file actions
68 lines (57 loc) · 1.72 KB
/
Copy pathvectorClass.cpp
File metadata and controls
68 lines (57 loc) · 1.72 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//Vector class STL
//dynamic array
/*
push_back(),pop_back(),at(),capacity() from() back();
*/
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <vector>
using namespace std;
int main()
{
system("cls");
//create a vector object
vector <string> vect{"pyhon","c++","java"};
//create a vector object with length
vector <int> vect1(3);
//create vector object and initilizing value
vector <char> vect2(5,10);
vector <string> vect3(5,"Hi");
//printing value
cout<<vect1[0]<<endl;
cout<<vect1[2]<<endl;
cout<<vect1[1]<<endl;
cout<<vect3[0]<<endl;
cout<<vect3[1]<<endl;
cout<<vect3[2]<<endl;
//printing value with loop
for(int i=0;i<3;i++)
{
cout<<vect[i]<<endl;
}
//checking capacity of vector
int cap1 = vect.capacity();
cout<<"vect capacity is \n"<<cap1<<endl;
//push_back() method adding value at the end
cout<<"push_back element "<<endl;
vect.push_back("C#"); //after pushing element capacity will be extend
cout<<"vect capacity is "<<vect.capacity()<<endl;
//remove the last element of vector capacity
cout<<"poping element \n"<<endl;
vect.pop_back();
vect.pop_back();
cout<<"After removing last element of vect "<<vect.capacity()<<endl;
//checking size of vector
cout<<"Vector size \n"<<endl;
cout<<"number of element of vector of vect "<<vect.size()<<endl;
//accessing all element of vector
for(int i=0;i<vect.size();i++)
cout<<"vect element is "<<vect[i]<<endl;
//iterator with vector
vector<int>::iterator pp= vect1.begin();
vect1.insert(pp,10);
for(int x=0;x<vect1.size();x++)
cout<<"vect1 element "<<vect1[x]<<endl;
system("pause");
}