母串中寻找字串
2018-09-13 本文已影响10人
带着白卡去旅行
find顺搜索
rfind逆搜索
string::npos表示母串中不含字串
index表示位置
#include<iostream>
#include<iomanip>
#include<string>
using namespace std;
void main()
{
string text = "had had sdsdsdhad";
string word = "had";
int count = 0;
for (int index = 0; (index = text.find(word, index)) != string::npos; index = word.length() + index, count++);
cout << count;
system("pause");
return;
}