C 判断字符串中是否包含某字符(串)

 


std::string a = "abjahjhaskajs_kajks";
std::string b = "_";
string::size_type idx;
idx = a.find(b);
if(idx == string::npos )
  cout<<"字符串中存在字符"_" <<endl;
else
  cout<<"不存在" <<endl;

 

 string a="abcdefghigklmn";
    char *b="def";
    char *c="123";
     
    if(strstr(a.c_str(), b) == NULL)//在a中查找b,如果不存在,
        cout << "not found\n";
    else//否则存在。
        cout <<"found\n";