'a'was found in "This is a test".
'z'was not found in "This is a test".

利用函数计算字符串1中出现字符串2的次数

 

#include <iostream>
using std::cout;
using std::endl;
int main()
{
char *string1="asdfasdfasdf";
const char *string2="df";
int i=0;
while (strstr(string1,string2)!=NULL)
{
++i;
string1
=strstr(string1,string2);
string1
+=strlen(string2);

}

cout
<<i<<endl;
return 0;
}

 

 

 

posted on 2010-05-08 16:52  c++我们一起学习  阅读(389)  评论(0编辑  收藏  举报