字符串查找包含某个字符串时一般通过find()查找,找到返回所在位置,找不到则会返回string::npos
示例代码:
string str;
if( str.find("a") != string::npos )
{
cout<<"找到"<<endl;
}
else
{
cout<<"未找到"<<endl;
}
字符串查找包含某个字符串时一般通过find()查找,找到返回所在位置,找不到则会返回string::npos
示例代码:
string str;
if( str.find("a") != string::npos )
{
cout<<"找到"<<endl;
}
else
{
cout<<"未找到"<<endl;
}