-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSTLvector.cpp
More file actions
54 lines (44 loc) · 1.1 KB
/
STLvector.cpp
File metadata and controls
54 lines (44 loc) · 1.1 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
#include <iostream>
#include <vector>
using namespace std;
int main(int argc, char const *argv[])
{
vector<int> v;
vector<int> a(5, 1);
vector<int> last(a);
for (int i : last)
{
cout << i << " ";
}
cout << endl;
cout << "Capacity " << v.capacity() << endl;
v.push_back(2);
cout << v[0] << endl;
cout << "Capacity " << v.capacity() << endl;
v.push_back(4);
cout << v[1] << endl;
cout << "Capacity " << v.capacity() << endl;
v.push_back(6);
cout << v[2] << endl;
cout << "Capacity " << v.capacity() << endl;
cout << "Size " << v.size() << endl;
cout << "2nd index element " << v.at(2) << endl;
cout << "Front " << v.front() << endl;
cout << "Back " << v.back() << endl;
cout << "Before pop " << endl;
for (int i : v)
{
cout << i << " ";
}
cout << endl;
v.pop_back();
cout << "After pop " << endl;
for (int i : v)
{
cout << i << " ";
}
cout << "Before clear size" << v.size() << endl;
v.clear();
cout << "After clear size" << v.size() << endl;
return 0;
}