asdds dsadsa
asdds dsadsa

Reputation: 49

STD c++ set using find function

Let's say I want to find the pointer to the element X in my set.I'll do:

set<int>S;
int x;
cin>>x;
//insert elements
set<int>iterator :: it = S.find(x);

How do i find element right after x in my set now?For example , if my set is :1 , 2 , 3 and x is 2 , I want to print 3.This doesn't seem to work:

cout<<*(it+1);

It says no match for operator '+'.Thanks!

Upvotes: 0

Views: 85

Answers (1)

selbie
selbie

Reputation: 104559

instead of this:

cout<<*(it+1);

This:

if (it != S.end()) {
    it++;
    if (it != S.end()) {
        cout << *it;
    }
}

Upvotes: 2

Related Questions