How to check if a set contains a given element in C++?
This video will teach two ways to check if an element is in a set or not.
The methods work for both set and unordered_set in the C++ STL.
Checking if an element is a member of a set is one of the most important operations on sets. In fact, it is often the main reason of using a set over a vector. If you have experience in other programming languages, you might expect a contains method, but sets don't have that in C++. The first approach demonstrated in this video uses the find method while the second uses the count method.
Chapters
0:00 - Intro
0:22 - Option 1 - Set.find
1:14 - Option 2 - Set.count
1:57 - Unordered sets
2:08 - Outro