-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvector_init.cpp
More file actions
39 lines (33 loc) · 882 Bytes
/
vector_init.cpp
File metadata and controls
39 lines (33 loc) · 882 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
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
void print(vector<int> vec) {
for_each(vec.begin(), vec.end(), [] (int v) { cout << v << " "; });
cout << endl;
}
void print(vector<vector<int>> vec2d) {
for (auto it = vec2d.begin(); it != vec2d.end(); it++) {
auto vec = *it;
for_each(vec.begin(), vec.end(), [] (int v) { cout << v << " "; });
cout << endl;
}
}
int main(int argc, char **argv) {
vector<int> vec {1, 2, 3, 4, 5, 6, 7};
vector<int> vec2(7, 4);
vector<vector<int>> vec3 {
{0, 0, 0, 0, 1, 0},
{0, 1, 0, 1, 0, 0},
{0, 0, 0, 1, 0, 1},
{0, 0, 1, 0, 0, 1},
{1, 0, 0, 0, 1, 0}
};
vector<int> left(vec.begin(), vec.begin() + 2);
cout << "vec: ";
print(vec);
cout << "vec2: ";
print(vec2);
print(vec3);
return 0;
}