-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPrint2DVectorAndArrayMatrix.cpp
More file actions
42 lines (34 loc) · 1013 Bytes
/
Print2DVectorAndArrayMatrix.cpp
File metadata and controls
42 lines (34 loc) · 1013 Bytes
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
// Print out the contents of a 2D matrices
// implemented using std::vector and std::array.
//
// Complier: Visual Studio 2013 (v120)
#include <iostream>
#include <vector>
#include <array>
using namespace std;
template <typename T>
void print(const vector<vector<T>> &a) {
for (const auto &i : a) {
for (const auto &j : i)
cout << j;
cout << endl;
}
}
template <typename T, size_t ROW, size_t COL>
void print(const array<array<T, COL>, ROW> &a) {
for (const auto &i : a) {
for (const auto &j : i)
cout << j;
cout << endl;
}
}
void main() {
cout << endl << "Printing vector based matrix" << endl;
auto vectorMatrix = vector<vector<int>> { { 1, 2, 3, 4 }, { 5, 6, 7, 8 }, { 8, 7, 2, 0 } };
print(vectorMatrix);
cout << endl << "Printing array based matrix" << endl;
array<std::array<int, 4>, 3> arrayMatrix{ { { { 1, 2, 3, 1 } }, { { 4, 5, 6, 4 } }, { { 7, 8, 9, 7 } } } };
print(arrayMatrix);
cout << endl << "[Press enter to exit]" << endl;
cin.ignore();
}