//vector查找到指定元素删除
std::vector<int> numbers{ 5, 46, -5, -6, 23, 17, 5, 9, 6, 5 };
int value{ 5 };
auto iter = std::find(std::begin(numbers), std::end(numbers), value);
if (iter != std::end(numbers))
{
numbers.erase(iter);
}
//vector的结构体中查找到指定元素
struct st {
int a;
int b;
st(int _a = 0, int _b = 0) : a(_a), b(_b) {}
};
bool operator == (const st& left, const st& rigt)
{
return left.b == rigt.b;
}
int main()
{
vector<st> vst;
vst.push_back(st(0, 1));
vst.push_back(st(0, 2));
vst.push_back(st(1, 2));
vst.push_back(st(5, 1));
vst.push_back(st(5, 5));
vst.push_back(st(5, 7));
st t;
t.b = 5;
vector<st>::iterator ifind;
int nPosition = 0;
ifind = vst.begin();
for (ifind = vst.begin(); ifind != vst.end(); ifind++)
{
ifind = find((vst.begin() + nPosition), vst.end(), t);
if (ifind != vst.end())
{
cout << "finded" << ifind->a << "-----" << ifind->b << endl;
nPosition = distance(vst.begin(), ifind) + 1;
continue;
}
break;
}
system("pause");
return 0;
}