user182513
user182513

Reputation:

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

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

What should i do?

Upvotes: 12

Views: 12461

Answers (1)

Kerrek SB
Kerrek SB

Reputation: 477040

Use lower_bound to compute std::distance(s.begin(), s.lower_bound(x)). (If x is a key, this counts the number of elements strictly before x.)

Upvotes: 20

Related Questions