Answers for "check if element is present in set c++"

C++
1

check if value exists in set c++

#include <iostream>
#include <unordered_set>
using namespace std;
 
int main()
{
    std::unordered_set<int> s = { 1, 2, 3, 4, 5 };
    int key = 3;
 
    if (s.find(key) != s.end()) {
        std::cout << "Element is present in the set" << std::endl;
    }
    else {
        std::cout << "Element not found" << std::endl;
    }
 
    return 0;
}
Posted by: Guest on August-23-2021
1

check if set contains element c++

set<T>::iterator it = theSet.find(element);
if (it != theSet.end())
{
  // The element was found
}
else
{
  // The element was not found
}
Posted by: Guest on May-21-2021
4

c++ find element in set

// initialize set
std::set<std::string> my_set({"foo", "bar"});
// find element in set
my_set.find("foo");
Posted by: Guest on November-28-2020

Code answers related to "check if element is present in set c++"

Browse Popular Code Answers by Language