-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample2.cpp
More file actions
44 lines (38 loc) · 885 Bytes
/
Copy pathexample2.cpp
File metadata and controls
44 lines (38 loc) · 885 Bytes
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
#include <iostream>
#include <string>
using namespace std;
class log {
public:
size_t size;
string* data;
log() {
size = 0;
data = new string[size + 1];
data[0] = "END";
}
// note: we omit the "big 3" here for readability only
void append(string msg) {
string* new_data = new string[size + 1];
for (size_t i = 0; i < size; i++) {
new_data[i] = data[i];
}
new_data[size] = msg;
new_data[size + 1] = "END";
size++;
}
void show() {
for (size_t i = 0; i < size; i++) {
cout << data[i] << endl;
}
}
};
int main() {
log messages;
messages.append("Good day");
messages.append("Yo!");
messages.append("Bon jour");
messages.append("Top of the morning");
messages.append("Hello");
messages.show();
return 0;
}