文字列を含むかどうか判定するには、string の find を使う。
見つからなかった場合は、std::string::npos を返す。
例
#include <iostream>
#include <string>
using namespace std;
int main ()
{
string str1 = "おはようございます";
string str2 = "よう";
int found = str1.find(str2);
if (found != std::string::npos) {
std::cout << "位置: " << int(found) << std::endl;
}
return 0;
}
結果
位置: 6