调试时一直显示无法读取字符串中的字符,怎么办啊,哪里出了问题
#include<stdio.h>
class String
{
char * p;
public:
String(const char *p1=NULL);
String(String & s);
String& operator =(String & s);
String operator +(String & s);
bool operator ==(String & s);
bool operator <(String & s);
bool operator >(String & s);
~String();
};
#include<iostream>
#include"string.h"
using namespace std;
String::String(const char *p1)
{
if(p1==NULL)
{p=new char[1];
*p='\0';
}
else
{
int len=strlen(p);
p=new char[len+1];
strcpy(p,p1);
}
}
String::String(String &s)
{
int len=strlen(s1.p);
p=new char[len+1];
strcpy(p,s1.p);
}
String& String::operator =(String &s)
{
delete []p;
int len=strlen(s2.p);
p=new char[len+1];
strcpy(p,s2.p);
return *this;
}
String String::operator +(String &s)
{
int len1=strlen(s3.p);
int len2=strlen(p);
String temp;
temp.p= new char[len1+len2+1];
strcpy(temp.p,p);
strcat(temp.p,s3.p);
return temp;
}
bool String::operator==(String & s)
{
if(strcmp(p,s.p)==0)
return true;
else return false;
}
bool String::operator>(String & s)
{
if(strcmp(p,s.p)>0)
return true;
else return false;
}
bool String::operator<(String &s)
{
if(strcmp(p,s.p)<0)
return true;
else return false;
}
String ::~String()
{
delete []p;
p=NULL;
}
#include"string.h"
using namespace std;
int main()
{
String s1;
return 0;
}