L
lps
Unregistered / Unconfirmed
GUEST, unregistred user!
下面的代码来自某一本书,是用来实现c++中strstr库函数的,出现如下错误:
error C2440: 'initializing' : cannot convert from 'const char *' to 'char *'
(请不用给我翻译这段ENGLISH)
#include <iostream.h>
char * strstr( const char * string, const char * pattern)
{
for(;*string;string++){
for (char * s=string,* p=pattern;
*s==*p&&*p&&*s;
s++,p++)
if(!*p)
return string;
}
return 0;
}
void main()
{
char * s1="this a test",*s2="is";
cout<<strstr(s1,s2)<<endl;
}
error C2440: 'initializing' : cannot convert from 'const char *' to 'char *'
(请不用给我翻译这段ENGLISH)
#include <iostream.h>
char * strstr( const char * string, const char * pattern)
{
for(;*string;string++){
for (char * s=string,* p=pattern;
*s==*p&&*p&&*s;
s++,p++)
if(!*p)
return string;
}
return 0;
}
void main()
{
char * s1="this a test",*s2="is";
cout<<strstr(s1,s2)<<endl;
}