关于c++
#include<iostream.h></iostream.h>#include<string.h></string.h>
class wang
{
public:
friend int main();
wang();
wang(wang&s);
wang operator=(wang&s);
wang operator==(wang&s);
wang operator<(wang&s);
wang operator>(wang&s);
wang operator+(wang&s);
chuanchang(wang&s);
char *charu(char *s1,char *s2,int a);
shanchu(wang&s);
zichuan(wang&s);
void GetNext(char *t,int *next);
}
wang operator==(wang&s1,wang&s2)
{
s1=s;
cout<<"请输入要比较的字符串s2:"<<endl; cin="cin"></endl;>>s2;
if((s2)==0)
return ture;
else
return false;
}
wang operator<(wang&s1,wang&s2)
{
s1=s;
cout<<"请输入要比较的字符串s2:"<<endl; cin="cin"></endl;>>s2;
if((s2)<0)
return ture;
else
return false;
}
wang operator>(wang&s1,wang&s2)
{
s1=s;
cout<<"请输入要比较的字符串s2:"<<endl; cin="cin"></endl;>>s2;
if((s2)>0)
return ture;
else
return false;
}
wang operator+(wang&s1,wang&s2)
{
s1=s;
cout<<"请输入想要连接的字符串:"<<endl; cin="cin"></endl;>>s2;
char*temp;
temp=new char[strlen(s1)+strlen(s2)+1];
strcpy(temp,s1);
strcat(temp,s2);
wang result(temp);
return result;
}
chuanchang(wang&s)
{
s1=s;
cout<<"该字符串的长度是:"<<strlen(s1)<<endl; char="char" charu="charu" s1="s1" s2="s2" a="a" int="int" a="a" s1="s;" cout="cout" cin="cin"></endl;>>s2;
cout<<"输入插入处的下标:"<<endl; cin="cin"></endl;>>a;
for(int m = 0;s1[m] != '\0';m++);
for(int n = 0;s2[n] != '\0';n++);
char *ch = new char [m + n];
int i,j;
for(i = 0;i <= a;i++)
ch[i] = s1[i];
for(j = 0;s2[j] != '\0';j++,i++)
ch[i] = s2[j];
for(j = a + 1;s1[j] != '\0';i++,j++)
ch[i] = s1[j];
ch[i] = '\0';
char *p = charu(s1,s2,a);
cout<<"插入后的字符串为:"<<p<<endl; shanchu="shanchu" s1="s;" int="int" i="i" for="0,j=0;s[i]!=0;i++,j++)if(s[j]"></endl;>='0'&&s[j]<'10')
i--;elses[i]=s[j];cout<<"字符串删除后输出是:"<<s<<endl;} zichuan="zichuan" s1="s;" int="int" start="start" cout="cout" cin="cin"></endl;}>>start;
cout<<"请输入子串的长度:"<<endl; cin="cin"></endl;>>n;
s3=s1.assign(s1,start-1,n);
cout<<s3.data()<<endl; void="void" getnext="getnext" s2="s2" next="next" s1="s;" cout="cout" cin="cin"></endl;>>s2;
int i = 1,j = 0;//设置初始下标i和j
int n = strlen(s2);//s2串的长度为n
next[0] = -1;
next[1] = 0;
while(i < n)
{
if((j == -1) || (s2[j] == s2[i]))
{next[++i] = ++j;}
else
{j = next[j];}
int KMP(char *s1,char *s2)
{
int n = strlen(s1); //输入s1串的长度n
int m = strlen(s2); //输入s2串的长度m
int *next = new int[m];
GetNext(s2,next);
for(int i=0,j=0;i<n&&j<m;) s1="s1" if="=" s1="=" s2="s2" i="i" j="j" else="else" j="next[j];}" return="return" j="=m?i-j:-1);" int="int" pos="pos" pos="KMP(s1,s2);" kmp="kmp" if="if" pos="pos" int="int" i="0;" cout="cout" cout="cout" while="while" strlen="strlen" cout="cout" i="i" cout="cout" else="else" cout="cout" return="return" void="void" main="main" int="int" num="0,s;" cout="cout" cin="cin"></m;)>>s;
while(num!=10)
{
cout<<"请选择功能序号:"<<endl; cout="cout"></endl;>比较是否相等 2>比较是否小于 3>比较是否大于 4>连接 5>求串长 6>串插入 7>串删除 8>求子串 9>串匹配 10>退出"<<endl; cin="cin"></endl;>>num;
if(num==1)bool operator==(wang&s1,wang&s2);
if(num==2)bool operator<(wang&s1,wang&s2);
if(num==3)bool operator>(wang&s1,wang&s2);
if(num==4)bool operator+(wang&s1,wang&s2);
if(num==5)chuanchang(wang&s);
if(num==6)char *charu(char *s1,char *s2,int a);
if(num==7)shanchu(wang&s);
if(num==8)zichuan(wang&s);
if(num==9)void GetNext(char *t,int *next);
}
}
有两处错误。不会改啊