-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path7_vectors.cpp
More file actions
52 lines (45 loc) · 1.24 KB
/
7_vectors.cpp
File metadata and controls
52 lines (45 loc) · 1.24 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
// 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);
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<<" ";
}
void assignFunction(vector<int> vInts, int in)
{
cout<<"\nassigning "<<in<<" and printing the vector\n";
vInts.assign(1, in);
printVector(vInts);
}
void pushBackFunction(vector<int> vInts, int in)
{
cout<<"\npush back "<<in<<" and printing the vector\n";
vInts.push_back(in);
printVector(vInts);
}
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;
}