0
int main(){
list<int> l1;
list<int> :: iterator l1_iter;
int v1 = 10;
int v2 = 5;
l1.push_back(v1);
l1.push_back(v2);
l1.push_back(50);
l1.push_back(100);
l1_iter = find(l1.begin(), l1.end(), 50);

I have written this code, i want to search 50 in my list. Is there away to know if i found or not?

  • 6
    Possible duplicate of [How to search for an element in an stl list?](https://stackoverflow.com/questions/4604136/how-to-search-for-an-element-in-an-stl-list) –  Jan 02 '19 at 02:39
  • See the other answers in the duplicate above, not only the accepted one, for examples testing existence. –  Jan 02 '19 at 02:40
  • Consider reading some [documentation](https://en.cppreference.com/w/cpp/algorithm/find). – Jesper Juhl Jan 02 '19 at 06:56

1 Answers1

2

std::find will return its second argument (l1.end() in this case) if the element is not found.

sfjac
  • 7,119
  • 5
  • 45
  • 69