-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathdraft_vector.cpp
More file actions
64 lines (49 loc) · 1.73 KB
/
Copy pathdraft_vector.cpp
File metadata and controls
64 lines (49 loc) · 1.73 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <iostream>
#include <map>
#include <vector>
#include <string>
#include <set>
#include "zcutils.cpp"
void test_vector_constructor()
{
// https://en.cppreference.com/w/cpp/container/vector/vector
std::cout << "\n# test_vector_constructor\n";
std::vector<std::string> z0 {"2", "23", "233"};
std::cout << "initializer from list: " << z0 << std::endl;
std::vector<std::string> z1(z0.begin(), z0.end());
std::cout << "iterator constructor: " << z1 << std::endl;
std::vector<std::string> z2(z0);
std::cout << "copy constructor: " << z2 << std::endl;
std::vector<std::string> z3(3, "233");
std::cout << "repeat constructor: " << z3 << std::endl;
std::vector<int> z4 = {2, 3};
z4.push_back(3);;
std::cout << ".capacity(): " << z4.capacity() << std::endl;
std::cout << ".size(): " << z4.size() << std::endl;
std::cout << "second elements: " << z4[1] << ", " << z4.at(1) << std::endl;
int sum = 0;
for (auto ind0 = z4.cbegin(); ind0 !=z4.cend(); ind0++){
sum += *ind0;
}
std::cout << "sum: " << sum << std::endl;
}
void test_vector_insert()
{
std::cout << "\n# test_vector_insert\n";
std::vector<int> z0 {2,23};
std::cout << "vector<int>{2,23}: " << z0 << std::endl;
z0.insert(z0.begin(), -2);
std::cout << ".insert(begin(), -2): " << z0 << std::endl;
z0.insert(z0.end(), 233);
std::cout << ".insert(end(), 233): " << z0 << std::endl;
z0.insert(z0.end(), {2333,2333});
std::cout << ".insert(end(), {2333,2333}): " << z0 << std::endl;
}
// g++ draft_vector.cpp -std=c++11 -o tbd00.exe
int main(int argc, char const *argv[])
{
std::cout << "draft_vector.cpp\n";
test_vector_constructor();
test_vector_insert();
return 0;
}