-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMyString.h
More file actions
50 lines (36 loc) · 1.06 KB
/
MyString.h
File metadata and controls
50 lines (36 loc) · 1.06 KB
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
#ifndef TICKET_SYSTEM_MYSTRING_H
#define TICKET_SYSTEM_MYSTRING_H
template<int T>
struct String {
char str[T];
bool operator<(const String &a) const {
return strcmp(str, a.str) < 0;
}
bool operator==(const String &a) const {
return strcmp(str, a.str) == 0;
}
bool operator!=(const String &a) const {
return !((*this) == a);
}
bool operator<=(const String &a) const {
return (*this < a || *this == a);
}
bool operator>(const String &a) const {
return strcmp(str, a.str) > 0;
}
bool operator>=(const String &a) const {
return (*this > a || *this == a);
}
friend std::istream &operator>>(std::istream &is, String &tmp) {
return is >> tmp.str;
}
friend std::ostream &operator<<(std::ostream &os, const String &tmp) {
return os << tmp.str;
}
String<T> &operator=(const String<T> &rhs) {
if (this != &rhs) { memcpy(str, rhs.str, sizeof(str)); }
return *this;
}
String()=default;
};
#endif //TICKET_SYSTEM_MYSTRING_H