forked from pezy/CppPrimer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ex14_18_StrVecMain.cpp
45 lines (33 loc) · 1.17 KB
/
ex14_18_StrVecMain.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
#include "ex14_18_StrVec.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;
}