-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvector.cpp
More file actions
62 lines (47 loc) · 1.51 KB
/
Copy pathvector.cpp
File metadata and controls
62 lines (47 loc) · 1.51 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
#include <iostream>
#include <vector>
using namespace std;
int main()
{
vector<int> v;
vector<int> a(5, 1); //a-> vector name, 5-> size of vector, 1-> 5 of elements are 1
cout << "print a" << endl;
for (int i : a)
{
cout << i << " "; //print a's element
}
cout << endl;
vector<int> last(a); //for copy a's element in last vector
cout << "print last" << endl;
for (int i : last)
{
cout << i << " ";
}
cout << endl;
cout << "Capacity-> " << v.capacity() << endl; //capacity mean vector capacity
v.push_back(1);
cout << "Capacity-> " << v.capacity() << endl;
v.push_back(2);
cout << "Capacity-> " << v.capacity() << endl;
v.push_back(3);
cout << "Capacity-> " << v.capacity() << endl; //capacity mean vector capacity
cout << "Size-> " << v.size() << endl; //size mean vector element
cout << "Elemetn at 2nd Index" << v.at(2) << endl;
cout << "front " << v.front() << endl; // print vector 1st element
cout << "back " << v.back() << endl; // print vector last element
cout << "before pop" << endl;
for (int i : v)
{
cout << i << " ";
}
cout << endl;
v.pop_back(); //for remove last element
cout << "after pop" << endl;
for (int i : v)
{
cout << i << " ";
}
cout << "before clear size " << v.size() << endl;
v.clear(); //for clear the vector size
cout << "after clear size " << v.size() << endl;
}