我正在try 判断字符串是否包含C语言中的子字符串,如下所示:
char *sent = "this is my sample example";
char *word = "sample";
if (/* sentence contains word */) {
/* .. */
}
在C++中用什么来代替string::find
呢?
我正在try 判断字符串是否包含C语言中的子字符串,如下所示:
char *sent = "this is my sample example";
char *word = "sample";
if (/* sentence contains word */) {
/* .. */
}
在C++中用什么来代替string::find
呢?
if(strstr(sent, word) != NULL) {
/* ... */
}
请注意,如果找到单词word
,strstr
将返回指向sent
中单词开头的指针.