We have a list
std::list<int> list;
// fill part of the list with 5
list.push_back(5);
list.push_back(5);
list.push_back(5);
// fill part of the list with 10
list.push_back(10);
list.push_back(10);
list.push_back(10);
// iterator that starts with 5
std::list<int>::iterator iterFiveBegin = list.begin();
//
std::list<int>::iterator iterEnd = list.end();
How can I get the iterator std::list<int>::iterator iterTenBegin of the list where it starts with "10"?
Firstly, don't use variable name list, try intList instead.
You may use std::find
std::list<int>::iterator it = std::find (intList.begin(), intList.end(), 10);
Per std::find documentation:
std::find
Return value
Iterator to the first element satisfying the condition or last if no such element is found.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With