本文共 584 字,大约阅读时间需要 1 分钟。
#include <cstdlib>#include <iostream>#include <cstdio>using namespace std;int const MAX = 100;int main(int argc, char *argv[]){ char str[MAX]; char *pCh; char buf[MAX]; cout << "please input one line string: " << endl; gets(str); cout << "please input a word to search: "; while(cin >> buf) { pCh = strstr(str, buf); if(pCh == NULL) cout << buf << " not found" << endl; else cout << buf << " found" << endl; } system("PAUSE"); return EXIT_SUCCESS;}
strstr返回找到的第一个位置的指针, 否则返回空...
参考链接:
转载地址:http://aykqb.baihongyu.com/