Skip to content

Commit 825a5de

Browse files
author
Torben
committed
files erstellt
1 parent 48cbb48 commit 825a5de

File tree

4 files changed

+82
-15
lines changed

4 files changed

+82
-15
lines changed

src/String.cpp

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#include <iostream>
2+
using namespace std;
3+
4+
#include "String.h"
5+
6+
String::String() {
7+
size = 0;
8+
str = new char[1];
9+
str[0] = '\0';
10+
}
11+
12+
String::String(char c) {
13+
size = 1;
14+
str = new char[2];
15+
str[0] = c;
16+
str[1] = '\0';
17+
}
18+
19+
String::String(const char *s) {
20+
// TODO
21+
}
22+
23+
String::String(const String& s) {
24+
// TODO
25+
}
26+
27+
String::~String() {
28+
delete[] str;
29+
}
30+
31+
char& String::operator[](int index) {
32+
// TODO
33+
}
34+
35+
String& String::operator=(String& s) {
36+
// TODO
37+
}
38+
39+
String& String::operator+=(String& s) {
40+
// TODO
41+
}

src/String.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#include <iostream>
2+
using namespace std;
3+
4+
class String {
5+
private:
6+
// 'String' is represented internally as a plain C-style string.
7+
int size;
8+
char* str;
9+
public:
10+
String();
11+
String(char c);
12+
String(const char *);
13+
String(const String&);
14+
~String();
15+
16+
char& operator[](int index);
17+
String& operator=(String&);
18+
String& operator+=(String&);
19+
20+
// make friend, so we can access private members
21+
friend ostream& operator<<(ostream &out, String &s);
22+
23+
};

src/StringClassCPP.cpp

Lines changed: 0 additions & 15 deletions
This file was deleted.

src/testString.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#include "String.h"
2+
3+
ostream& operator<<(ostream &out, String &s) {
4+
for (int i = 0; i < s.size; i++) {
5+
out << s.str[i];
6+
}
7+
8+
return out;
9+
}
10+
11+
int main() {
12+
String s;
13+
String s2('H');
14+
15+
cout << s << endl;
16+
cout << s2 << endl;
17+
18+
}

0 commit comments

Comments
 (0)