-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmystring.cpp
54 lines (43 loc) · 860 Bytes
/
mystring.cpp
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
/*************************************************************************
> File Name: mystring.cpp
> Author: huwq
> Mail:[email protected]
> Created Time: 2014年04月18日 星期五 15时14分08秒
************************************************************************/
#include "mystring.h"
namespace mystring {
string::string()
{
_str = new char;
_str[0] = 0;
}
string::string(const char* s)
{
_str = new char[strlen(s) + 1];
strcpy(_str, s);
}
string::string(const string& s)
{
_str = new char[s.size() + 1];
strcpy(_str, s._str);
}
std::size_t string::size() const
{
return strlen(_str);
}
void string::debug()
{
std::cout << _str << std::endl;
}
string::string()
{
delete [] _str;
}
string& string::operator=(const string &s)
{
delete[] _str;
_str = new char[s.size() + 1];
strcpy(_str, s._str);
return *this;
}
}