📅  最后修改于: 2020-09-25 09:15:55             🧑  作者: Mango
const char* strstr( const char* str, const char* target );
char* strstr( char* str, const char* target );
strstr()
函数采用两个参数: str
和target
。它在str
指向的字符串搜索target
的第一个匹配项。终止的空字符将被忽略。
它在
#include
#include
using namespace std;
int main()
{
char str[] = "Use your brain and heart";
char target[] = "brain";
char *p = strstr(str, target);
if (p)
cout << "'" << target << "' is present in \"" << str << "\" at position " << p-str;
else
cout << target << " is not present \"" << str << "\"";
return 0;
}
运行该程序时,输出为:
'brain' is present in "Use your brain and heart" at position 9