c++字符串匹配问题

来源:百度知道 编辑:UC知道 时间:2024/06/21 22:43:51
int String::find(String &p) //检索
{
int i=0;
if(i<0 || i>n-1) //越界检查
{
cout<<"out of bound !"<<endl;
return -1;
}
char *pp=p.str; //模式串指针pp指向第一个字符
char *t=str+i; //主串指针t指向下标为i的字符
while(*pp!='\x0' && i<=n-p.n)
{
if(*pp++!=*t++)
{
pp=p.str;
t=str+(++i);
}

if(*pp='\0')
return i;
return -1;
}
}
在main函数String f("welcom");
String k("el");
cout<<f.find (k)<<endl;
为什么不行???急~~~

逻辑完全混乱。。。

一上来就震慑了我了
int i=0;
if(i<0 || i>n-1) //越界检查 这也检查的太勤快了,上一句赋值0,下一句检查是不是小于0了。。

是标准库的string么.....小写的...兄台

标记