Question about set in cpp

If I remove an element that is not present in a set will it give an exception?

First of all how can you do that ??
:slight_smile:

if i created a set inserted some elements . erase one element that may be or may not be in set.If element is not present will it throw exception?

Why don’t you simply try doing that ? Or why don’t you Google search ?

Afaik it doesn’t give any exception.

2 Likes

that only how do you remove I asked
I don’t think it is possible
:slight_smile:

sir,like this:

set st;
st.insert(5);
st.erase(4);

First check whether that element is included in set or not, and then erase, like this:

set <long long> st;
st.insert(10);
if(st.count(8) == 0) {
    cout << "Element not found" << endl;
else {
    st.erase(8);
    cout << "Element found" << endl;
}