-
Notifications
You must be signed in to change notification settings - Fork 0
/
TwoDVector.cpp
executable file
·58 lines (48 loc) · 1.22 KB
/
TwoDVector.cpp
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
#include <iostream>
#include <vector>
using namespace std;
void printVectorInt(const vector<int>& vec)
{
for (auto v : vec)
{
cout << v << ", ";
}
cout << endl;
}
int main()
{
// Add elements to TwoD vector and print it
{
cout << endl << "Case 1" << endl;
uint32_t rows = 2;
uint32_t cols = 3;
vector< vector<int> > myTwoDVec(rows, vector<int> (cols, 5));
for (uint32_t i = 0; i < rows; i++)
{
for (uint32_t j = 0; j < cols; j++)
{
cout << myTwoDVec[i][j] << " ";
}
cout << endl;
}
vector< vector<bool> > myTwoDBoolVec(rows, vector<bool> (cols, false));
for (uint32_t i = 0; i < rows; i++)
{
for (uint32_t j = 0; j < cols; j++)
{
cout << myTwoDBoolVec[i][j] << " ";
}
cout << endl;
}
}
// Adding at a random point to a vector
{
cout << endl << "Case 2" << endl;
vector<int> vec;
vec.reserve(10);
cout << vec.size() << endl;
// The below line crashes the program
//vec.insert(vec.begin() + 2, 5);
printVectorInt(vec);
}
}