How to check if an item exists in a set with C++

1 Answer

0 votes
#include <iostream>
#include <set>  

int main()
{
    std::set<char> st = {'a', 'b', 'c', 'd', 'e', 'f', 'g'};  
    
    if (st.find('h') == st.end()) {
        std::cout << "Not Found";
    } else {
        std::cout << "Found";
    }
    
}



/*
run:

Not Found
  
*/

 



answered Feb 20, 2024 by avibootz
...