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!
instead of this:
cout<<*(it+1);
This:
if (it != S.end()) {
it++;
if (it != S.end()) {
cout << *it;
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.