forked from Mooophy/Cpp-Primer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ex3_21.cpp
51 lines (43 loc) · 1.08 KB
/
ex3_21.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
//
//Redo the first exercise from § 3.3.3 (p. 105) using iterators.
//
#include <vector>
#include <iterator>
#include <string>
#include <iostream>
using std::vector;
using std::string;
using std::cout;
using std::endl;
void check_and_print(const vector<int>& vec)
{
cout << "size: " << vec.size() << " content: [";
for (auto it = vec.begin(); it != vec.end(); ++it)
cout << *it << (it != vec.end() - 1 ? "," : "");
cout << "]\n" << endl;
}
void check_and_print(const vector<string>& vec)
{
cout << "size: " << vec.size() << " content: [";
for (auto it = vec.begin(); it != vec.end(); ++it)
cout << *it << (it != vec.end() - 1 ? "," : "");
cout << "]\n" << endl;
}
int main()
{
vector<int> v1;
vector<int> v2(10);
vector<int> v3(10, 42);
vector<int> v4{ 10 };
vector<int> v5{ 10, 42 };
vector<string> v6{ 10 };
vector<string> v7{ 10, "hi" };
check_and_print(v1);
check_and_print(v2);
check_and_print(v3);
check_and_print(v4);
check_and_print(v5);
check_and_print(v6);
check_and_print(v7);
return 0;
}