-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstring.h
More file actions
89 lines (66 loc) · 1.34 KB
/
string.h
File metadata and controls
89 lines (66 loc) · 1.34 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#pragma once
class string
{
private:
char* data = nullptr;
int n = 0;
public:
string()
{
}
string(int n, const char a) :n(n)
{
data = new char[n];
for (int i = 0; i < this->n; i++)
{
this->data[i] = a;
}
}
string(const char* arr)
{
int k = 0;
while (arr[k] != '\0')
{
k++;
}
this->n = k;
this->data = new char[k];
for (int i = 0; i < this->n; i++)
{
data[i] = arr[i];
}
}
string(const string& v) :n(v.n)
{
data = new char[v.n];
for (int i = 0; i < v.n; i++)
{
this->data[i] = v.data[i];
}
}
void print() const;
int len() const;
char& operator[](const int& index) const;
bool empty() const;
void clear();
void erase(int index, int n_s = 1);
void insert(int pos, const char* ch, int len = 1);
void insert(int pos, const string& str);
string substr(int pos, int len) const;
int find(const string& str);
int* prefix(const string& v);
bool operator==(const string& str) const;
bool operator!=(const string& str) const;
bool operator<(const string& str) const;
bool operator<=(const string& str) const;
bool operator>(const string& str) const;
bool operator>=(const string& str) const;
string operator+(const string& v) const;
string operator+(const char* arr);
string& operator+=(const string& v);
string& operator=(const string& v);
~string()
{
delete[] data;
}
};