-
Notifications
You must be signed in to change notification settings - Fork 0
/
string.h
executable file
·69 lines (54 loc) · 2.44 KB
/
string.h
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
65
66
67
68
69
//string.h
//Max Smiley
//Program # 3;
//cs202
//string is a class very closely mirroring the functionality of the string class inthe standard library.
//I mainly used this as an exercise to have some practice with the implementation of the various operators
//and to avoid having to deal with cstrings everywhere in the program.
#include <iostream>
using namespace std;
class String
{
public:
String();
String(const String& to_copy);
String(const char * c_string);
~String();
//asignment
String & operator=(const String& to_copy);
String & operator=(const char* to_copy);
//addition
friend String operator+(const String& string, const char* c_string);
friend String operator+(const char* c_string, const String& string);
friend String operator+(const String& string1, const String& string2);
String & operator+=(const String& in_string);
String & operator+=(const char* c_string);
//extraction and insertion
friend istream & operator>>(istream& in, String& string);
friend ostream & operator<<(ostream& out, const String& string);
//subscript operator
char& operator[](int) const;
//logical operators
friend bool operator<(const String& string, const char* c_string);
friend bool operator<(const char* c_string, const String& string);
friend bool operator<(const String& string1, const String& string2);
friend bool operator<=(const String& string, const char* c_string);
friend bool operator<=(const char* c_string, const String& string);
friend bool operator<=(const String& string1, const String& string2);
friend bool operator>(const String& string, const char* c_string);
friend bool operator>(const char* c_string, const String& string);
friend bool operator>(const String& string1, const String& string2);
friend bool operator>=(const String& string, const char* c_string);
friend bool operator>=(const char* c_string, const String& string);
friend bool operator>=(const String& string1, const String& string2);
friend bool operator!=(const String& string, const char* c_string);
friend bool operator!=(const char* c_string, const String& string);
friend bool operator!=(const String& string1, const String& string2);
friend bool operator==(const String& string, const char* c_string);
friend bool operator==(const char* c_string, const String& string);
friend bool operator==(const String& string1, const String& string2);
protected:
int len;
char * str;
explicit String(char* to_copy);
};