很奇怪的编译有关问题,return 0 之前都是对的,运行到return 0后就出错,求大神解答

很奇怪的编译问题,return 0 之前都是对的,运行到return 0后就出错,求大神解答!
#include <string.h> 
#include <stdlib.h> 
#include <string> 
#include <iostream> 
using namespace std;
int lenth(char *str)
{
int l = 0;
for (int i = 0; str[i] != '\0'; i++)
l++;
return l;
}
void COpy(char*s1, char*s2)
{
int t2 = lenth(s2);
for (int i = 0; i < t2; i++)
s1[i] = s2[i];
s1[t2] = '\0';
}
class MyString
{
int len;
char *p;
public:
MyString()
{
p = new char[1];
len = 1;
p[0] = '\0';
}
MyString(char*s);
MyString(MyString & a)
{
p = new char[lenth(a.p) + 1];
COpy(p, a.p);
len = a.len;
}
/*~MyString()
{
if (p)
delete[]p;
}*/
int operator<(MyString & a);
int operator == (MyString & a);
int operator >(MyString & a);
char & operator [] (int i);
MyString operator + (char *s);
MyString & operator += (char *s);
MyString & operator = (MyString & a);
MyString & operator = (char *s);
friend MyString operator + (MyString &a, MyString &b);
friend MyString operator + (char *s, MyString &a);
MyString operator () (int i, int j);
friend ostream & operator << (ostream & o, const MyString & s);
};
MyString & MyString::operator += (char *s)
{
char *q;
q = new char[lenth(p) + lenth(s) + 1];
COpy(q, p);
for (int i = lenth(p); i < lenth(p) + lenth(s); i++)
q[i] = s[i - lenth(p)];
q[lenth(p) + lenth(s)] = '\0';
if (p)
delete []p;
p = new char[lenth(q) + 1];
COpy(p, q);
len = lenth(q);
delete[]q;
return *this;
}
MyString & MyString::operator = (MyString & a)
{
if (p)
delete[]p;
p = new char[a.len + 1];
COpy(p, a.p);
len = a.len;
return *this;
}
MyString & MyString::operator = (char *s)
{
if (p)
delete[]p;
p = new char[lenth(s) + 1];
COpy(p, s);
len = lenth(s);
return *this;
}
MyString::MyString(char *s)
{
p = new char[lenth(s) + 1];
COpy(p, s);
len = lenth(s);
}
int MyString::operator< (MyString & a)
{
if (len > a.len)
{
for (int i = 0; i < a.len; i++)
{
if (p[i] < a.p[i])
return 1;
if (p[i] > a.p[i])
return 0;
}
return 0;
}
else
{
for (int i = 0; i < len; i++)
{
if (p[i] < a.p[i])
return 1;
if (p[i] > a.p[i])
return 0;
}
return 0;
}
}
int MyString::operator== (MyString & a)
{
if (len != a.len)
return 0;
else
{
for (int i = 0; i < len; i++)
{
if (p[i] != a.p[i])
return 0;
}
return 1;
}
}
int MyString::operator>(MyString & a)
{
{
if (len < a.len)
{
for (int i = 0; i < len; i++)
{
if (p[i] > a.p[i])
return 1;
if (p[i] < a.p[i])
return 0;
}
return 0;
}
else
{
for (int i = 0; i < a.len; i++)
{
if (p[i] > a.p[i])
return 1;
if (p[i] < a.p[i])
return 0;
}
return 0;
}
}
}
char & MyString::operator [](int i)
{
return p[i];
}
MyString operator + (MyString &a, MyString &b)
{
char *q;
q = new char[lenth(a.p) + lenth(b.p) + 1];
COpy(q, a.p);
for (int i = lenth(a.p); i < lenth(a.p) + lenth(b.p); i++)
q[i] = b.p[i - lenth(a.p)];
q[lenth(a.p) + lenth(b.p)] = '\0';
MyString tmp(q);
delete[]q;
return tmp;
}
MyString operator + (char *s, MyString &a)
{
char *q;