#include<iostream>
using namespace std;
#include<vector>
#include<algorithm>
//adjacent_find(iterator begin,iterator end)
//查找相邻重复元素,返回相邻元素的第一个位置的迭代器,未查找到返回结束迭代器end
//begin为开始迭代器 end为结束迭代器
void test0501()
{
vector<int> v;
v.push_back(0);
v.push_back(2);
v.push_back(0);
v.push_back(1);
v.push_back(0);
v.push_back(4);
v.push_back(1);
v.push_back(2);
vector<int>::iterator it=adjacent_find(v.begin(), v.end());
if (it == v.end())
{
cout << "未找到" << endl;
}
else
{
cout << "找到了" << (*it) << endl;
}
}
int main()
{
test0501();
system("pause");
return 0;
}
网友评论