Search for Data in a Set in C++

#include <iostream>
#include <set>
using namespace std;

int main()
{
    set<int> s = {78, 8, 9, 4, 5, 3, 65, 40};
    int value = 40;
    auto found = s.find(value);
    if (found != s.end())
    {
        cout << "Value found!" << endl;
        s.erase(found);
        cout << "Element deleted." << endl;
    }
    else
    {
        cout << "Value not found!" << endl;
    }

    for (auto e : s)
    {
        cout << e << endl;
    }
    return 0;
}

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *