find 返回的只是第一个符合条件的迭代器
一、vector中查找特定值
如果搜索成功,则返回对应的迭代器
如果搜索失败,则返回第二个参数的迭代器
using namespace std;
vector<int> v = { 1,2,3,4,5,6,7 };
int val = 4;
auto result = find(v.begin(), v.end(), val);
//返回的是指向4 的迭代器
cout << *result << endl;
二、list中查找给定的string串
反向迭代器
using namespace std;
list<string> lst = {"hello","world","Good","Today"};
string tmp = "Good";
auto resualt = find(lst.cbegin(), lst.cend(), tmp);
//返回的是对应的迭代器
cout << *resualt << endl;
三、find在一个string中 查找特定的字符
和vector用法类似
string tmp = "hello world!";
char ch = 'w';
auto resualt = find(tmp.begin(), tmp.end(), ch);
//返回的是对应的迭代器
cout << *resualt << endl;
四、find在数组中查找
using namespace std;
int _ia[] = { 23,45,66,78,90 };
int tmp = 90;
auto resualt = find(_ia, _ia + 4, tmp);
cout << *resualt << endl;
或者
using namespace std;
int _ia[] = { 23,45,66,78,90 };
int tmp = 90;
auto resualt = find(begin(_ia), end(_ia), tmp);
cout << *resualt << endl;
返回的都是对应的指针。
仅个人观点,希望指正!