| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 312 人关注过本帖
标题:关于c++
只看楼主 加入收藏
xu1990912
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2011-6-1
结帖率:50%
收藏
已结贴  问题点数:10 回复次数:1 
关于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&lt;(wang&s);
wang operator&gt;(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&lt;&lt;"请输入要比较的字符串s2:"&lt;<endl; cin="cin"></endl;>&gt;s2;
if((s2)==0)
return ture;
else
return false;
}
wang operator&lt;(wang&s1,wang&s2)
{
s1=s;
cout&lt;&lt;"请输入要比较的字符串s2:"&lt;<endl; cin="cin"></endl;>&gt;s2;
if((s2)&lt;0)
return ture;
else
return false;
}
wang operator&gt;(wang&s1,wang&s2)
{
s1=s;
cout&lt;&lt;"请输入要比较的字符串s2:"&lt;<endl; cin="cin"></endl;>&gt;s2;
if((s2)&gt;0)
return ture;
else
return false;
}
wang operator+(wang&s1,wang&s2)
{
s1=s;
cout&lt;&lt;"请输入想要连接的字符串:"&lt;<endl; cin="cin"></endl;>&gt;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&lt;&lt;"该字符串的长度是:"&lt;&lt;strlen(s1)&lt;<endl; char="char" charu="charu" s1="s1" s2="s2" a="a" int="int" a="a" s1="s;" cout="cout" cin="cin"></endl;>&gt;s2;
cout&lt;&lt;"输入插入处的下标:"&lt;<endl; cin="cin"></endl;>&gt;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 &lt;= 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&lt;&lt;"插入后的字符串为:"&lt;&lt;p&lt;<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]&lt;'10')
i--;elses[i]=s[j];cout&lt;&lt;"字符串删除后输出是:"&lt;&lt;s&lt;<endl;} zichuan="zichuan" s1="s;" int="int" start="start" cout="cout" cin="cin"></endl;}>&gt;start;
cout&lt;&lt;"请输入子串的长度:"&lt;<endl; cin="cin"></endl;>&gt;n;
s3=s1.assign(s1,start-1,n);
cout&lt;&lt;s3.data()&lt;<endl; void="void" getnext="getnext" s2="s2" next="next" s1="s;" cout="cout" cin="cin"></endl;>&gt;s2;
int i = 1,j = 0;//设置初始下标i和j
int n = strlen(s2);//s2串的长度为n
next[0] = -1;
next[1] = 0;
while(i &lt; 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&lt;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;)>&gt;s;
while(num!=10)
{
cout&lt;&lt;"请选择功能序号:"&lt;<endl; cout="cout"></endl;>比较是否相等       2&gt;比较是否小于       3&gt;比较是否大于       4&gt;连接       5&gt;求串长       6&gt;串插入       7&gt;串删除       8&gt;求子串       9&gt;串匹配       10&gt;退出"&lt;<endl; cin="cin"></endl;>&gt;num;
if(num==1)bool operator==(wang&s1,wang&s2);
if(num==2)bool operator&lt;(wang&s1,wang&s2);
if(num==3)bool operator&gt;(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);
}
}
有两处错误。不会改啊
搜索更多相关主题的帖子: friend 字符串 
2011-06-18 18:24
南国利剑
Rank: 12Rank: 12Rank: 12
等 级:贵宾
威 望:29
帖 子:1165
专家分:3536
注 册:2010-4-12
收藏
得分:10 
回复 楼主 xu1990912
报错信息是什么呢?

南国利剑
2011-06-18 19:46
快速回复:关于c++
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.026661 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved