CString::CString(char*p) {
int n = strlen(p);
s = new char[n+1];
strcpy_s(s,n+1, p);
}
CString::CString(const char*p) {
int n = strlen(p);
s = new char[n + 1];
strcpy_s(s, n + 1, p);
}
CString::CString(int i) {
char ss[20];
sprintf_s(ss,20, "%d", i);
int n = strlen(ss);
s = new char[n+1];
strcpy_s(s,n+1, ss);
}
CString& CString::operator+(char*p){
if (!p) return *this;
int n = strlen(p);
if (!s) {
s = new char[n + 1];
strcpy_s(s, n + 1, p);
return *this;
}
int n1 = strlen(s);
char*pp = new char[n + n1 + 1];
strcpy_s(pp,n+n1+1, s);
strcat_s(pp, n + n1+1, p);
delete[]s;
s = pp;
return *this;
}
CString& CString::operator+(const char*p) {
if (!p) return *this;
int n = strlen(p);
if (!s) {
s = new char[n + 1];
strcpy_s(s, n + 1, p);
return *this;
}
int n1 = strlen(s);
char*pp = new char[n + n1 + 1];
strcpy_s(pp, n + n1 + 1, s);
strcat_s(pp, n + n1 + 1, p);
delete[]s;
s = pp;
return *this;
}
CString& CString::operator+=(const char*p) {
if (!p) return *this;
int n = strlen(p);
if (!s) {
s = new char[n + 1];
strcpy_s(s, n + 1, p);
return *this;
}
int n1 = strlen(s);
char*pp = new char[n + n1 + 1];
strcpy_s(pp, n + n1 + 1, s);
strcat_s(pp, n + n1 + 1, p);
delete[]s;
s = pp;
return *this;
}
CString& CString::operator+=(char*p) {
if (!p) return *this;
int n = strlen(p);
if (!s) {
s = new char[n + 1];
strcpy_s(s, n + 1, p);
return *this;
}
int n1 = strlen(s);
char*pp = new char[n + n1 + 1];
strcpy_s(pp, n + n1 + 1, s);
strcat_s(pp, n + n1 + 1, p);
delete[]s;
s = pp;
return *this;
}
CString& CString::operator=(char*p) {
if (!p) return *this;
int n = strlen(p);
if (s) delete[]s;
s = new char[n + 1];
strcpy_s(s, n + 1, p);
return *this;
}
CString& CString::operator=(const char*p) {
if (!p) return *this;
int n = strlen(p);
if (s) delete[]s;
s = new char[n + 1];
strcpy_s(s, n + 1, p);
return *this;
}
CString& CString::operator+(int i) {
char ss[20];
sprintf_s(ss, 20, "%d", i);
int n = strlen(ss);
if (!s) {
s = new char[n + 1];
strcpy_s(s, n + 1, ss);
return *this;
}
int n1 = strlen(s);
char*p = new char[n + n1 + 1];
strcpy_s(p,n+n1+1, s);
strcat_s(p,n+n1+1, ss);
delete[]s;
s = p;
return *this;
}
CString& CString::operator+=(int i) {
//return operator+(i);
char ss[20];
sprintf_s(ss, 20, "%d", i);
int n = strlen(ss);
if (!s) {
s = new char[n + 1];
strcpy_s(s, n + 1, ss);
return *this;
}
int n1 = strlen(s);
char*p = new char[n + n1 + 1];
strcpy_s(p, n + n1 + 1, s);
strcat_s(p, n + n1 + 1, ss);
delete[]s;
s = p;
return *this;
}
CString& CString::operator=(int i) {
//return operator+(i);
char ss[20];
sprintf_s(ss, 20, "%d", i);
int n = strlen(ss);
if (s) delete[]s;
s = new char[n + 1];
strcpy_s(s, n + 1, ss);
return *this;
}
CString& CString::operator+(CString& a) {
char*p = a.get();
if (!p) return *this;
int n = strlen(p);
if (n<1) return *this;
if (!s) {
s = new char[n + 1];
strcpy_s(s, n + 1,p);
return *this;
}
int n1 = strlen(s);
char*pp = new char[n + n1 + 1];
strcpy_s(pp, n + n1 + 1, s);
strcat_s(pp, n + n1 + 1, p);
delete[]s;
s = pp;
return *this;
}
CString& CString::operator+=(CString& a) {
return operator+(a);
}
CString& CString::operator=(CString& a) {
char*p = a.get();
if (!p) return *this;
int n = strlen(p);
if (n<1) return *this;
if (this == &a) {//s=s+...格式
return *this;
}
if (s) delete[]s;
s = new char[n + 1];
strcpy_s(s, n + 1, p);
return *this;
}