//在字符串中查找指定子串出现的次数
#include <iostream>
#include <string>
using namespace std;
int main() {
string str ;
getline(cin,str);
string target;
getline(cin,target);
int cnt = 0;
int pos = 0;//或者size_t pos=0;
while ((pos = str.find(target, pos)) != -1) {
//或者将-1改为string::npos
++cnt;
++pos;
}
cout << "The target string appears " << cnt << " times." << endl;
return 0;
}
//在字符串中查找指定字符出现的次数
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main() {
string str;
getline(cin,str);
char target;
cin>>target;
int cnt = count(str.begin(), str.end(), target);
cout << "The target character appears " << cnt << " times." << std::endl;
return 0;
}