File tree Expand file tree Collapse file tree 4 files changed +82
-15
lines changed
Expand file tree Collapse file tree 4 files changed +82
-15
lines changed Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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+ };
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments