c++ 怎样判断字符串string里面是否含有某个字符串

如题所述

使用 string 的 find 成员函数。 
#include <iostream>
#include <string>
using namespace std;
int main()
{
string str = "afdsdfs_hello_sdfas#@!";
string str1 = "hello";

string::size_type idx = str.find( str1 );

if ( idx != string::npos )
{
cout << "字符串含有“<< str1 << "\n";
}
else
{
cout << "字符串没有" << str1 << "\n";
}
}

温馨提示:答案为网友推荐,仅供参考
相似回答