forked from jaege/Cpp-Primer-5th-Exercises
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path13.44.cpp
38 lines (32 loc) · 953 Bytes
/
13.44.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
#include <iostream>
#include "String.h"
void print(const String &s) {
std::cout << "<" << &s << ">:<" << s.str() << "> size: "
<< s.size() << " capacity: " << s.capacity() << std::endl;
}
int main() {
String s1; print(s1);
s1.pop_back(); print(s1);
s1.push_back('a'); print(s1);
s1.push_back('b'); print(s1);
s1.push_back('c'); print(s1);
s1.push_back('d'); print(s1);
{
String s2 = "s2"; print(s2);
s2 = "s3"; print(s2);
char *cs = "def";
s2 = cs; print(s2);
s2 = s1; print(s2);
}
print(s1);
s1.pop_back(); print(s1);
s1.reserve(s1.capacity() / 2); print(s1);
s1.reserve(s1.capacity() * 2); print(s1);
s1.resize(s1.size() + 6); print(s1);
s1.resize(s1.size() + 6, 'x'); print(s1);
s1.resize(s1.size() - 6); print(s1);
s1.resize(s1.size() - 6, 'x'); print(s1);
String s2 { 'm', 'n', 'p', 'q', 'r' }; print(s2);
String s3 = { 'm', 'n', 'p', 'q', 'r' }; print(s3);
return 0;
}