find();
a串中,b串完全匹配才返回位置,不然返回string::npos.
#include <string >
#include <iostream>
using namespace std;
int main()
{
string a="123456789";
cout<<a.find("10");
cout<<endl;
cout<<string::npos;
return 0;
}
还有四个函数:
根据字面意思可使用
find_first_of()
find_first_not_of()
find_last_of()
find_last_not_of()
本文介绍了C++标准库中字符串类的find()方法及其相关函数的使用方法。find()用于在字符串中搜索子串,若找到则返回子串的位置,否则返回string::npos。此外还介绍了find_first_of(), find_first_not_of(), find_last_of(), find_last_not_of()等函数,这些函数提供了更多的字符串搜索选项。
2320

被折叠的 条评论
为什么被折叠?



