检查C中的字符串中是否存在子字符串我正在尝试检查字符串是否在C中包含子字符串,例如:char *sent = "this is my sample example";char *word = "sample";if (/* sentence contains word */) { /* .. */}用什么代替string::findC ++?
4 回答

守候你守候我
TA贡献1802条经验 获得超10个赞
if(strstr(sent, word) != NULL) {
/* ... */
}
注意,如果找到strstr单词,sent则返回指向单词in的指针word。
- 4 回答
- 0 关注
- 767 浏览
添加回答
举报
0/150
提交
取消