C ++ set - the number of elements with a key less than x

I have set<int>, and I want to see how many elements there are less than x in it. (x also int)

What should I do?

+5
source share
1 answer

Use lower_boundto calculate std::distance(s.begin(), s.lower_bound(x)). (If xis the key, this counts the number of elements strictly up to x.)

+14
source

All Articles