-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvector2.cpp
More file actions
60 lines (49 loc) · 1.31 KB
/
vector2.cpp
File metadata and controls
60 lines (49 loc) · 1.31 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
// constructing vectors
// constructing vectors
#include <iostream>
#include <vector>
using namespace std;
void printVector(vector<int> vIn);
void assignFunction(vector<int> vInts, int in);
void pushBackFunction(vector<int> vInts, int in);
void emplaceFunction(vector<int> vInts, int loc, int in);
//print vectpr
void printVector(vector<int> vIn)
{//printing the contents of vIns
vector<int>::iterator it;
for (it = vIn.begin(); it != vIn.end(); ++it)
std::cout<<*it<<" ";
}
//assign in vector
void assignFunction(vector<int> vInts, int in)
{
cout<<"\nassigning "<<in<<" and printing the vector\n";
vInts.assign(1, in);
printVector(vInts);
}
//push_back
void pushBackFunction(vector<int> vInts, int in)
{
cout<<"\npush back "<<in<<" and printing the vector\n";
vInts.push_back(in);
printVector(vInts);
}
//emplace
void emplaceFunction(vector<int> vInts, int loc, int in)
{
vector<int>::iterator it;
cout<<"\nemplacing "<<in<<" and printing the vector\n";
it = vInts.begin() + loc;
vInts.emplace(it, in);
printVector(vInts);
}
int main ()
{
vector<int> vInts;
vInts.assign(10, 5);
printVector(vInts);
assignFunction(vInts, 1);
pushBackFunction(vInts, 2);
emplaceFunction(vInts,1, 3);
return 0;
}