forked from Mooophy/Cpp-Primer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ex14_23_TEST.cpp
46 lines (34 loc) · 1.18 KB
/
ex14_23_TEST.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
#include "ex14_23.h"
#include <iostream>
#include <vector>
int main()
{
StrVec vec;
vec.reserve(6);
std::cout << "capacity(reserve to 6): " << vec.capacity() << std::endl;
vec.reserve(4);
std::cout << "capacity(reserve to 4): " << vec.capacity() << std::endl;
vec.push_back("hello");
vec.push_back("world");
vec.resize(4);
for (auto i = vec.begin(); i != vec.end(); ++i)
std::cout << *i << std::endl;
std::cout << "-EOF-" << std::endl;
vec.resize(1);
for (auto i = vec.begin(); i != vec.end(); ++i)
std::cout << *i << std::endl;
std::cout << "-EOF-" << std::endl;
StrVec vec_list{ "hello", "world", "pezy" };
for (auto i = vec_list.begin(); i != vec_list.end(); ++i)
std::cout << *i << " ";
std::cout << std::endl;
// Test operator==
const StrVec const_vec_list = { "hello", "world", "pezy" };
if (vec_list == const_vec_list)
for (const auto &str : const_vec_list)
std::cout << str << " ";
std::cout << std::endl;
// Test operator<
const StrVec const_vec_list_small = { "hello", "pezy", "ok" };
std::cout << (const_vec_list_small < const_vec_list) << std::endl;
}