#include
#include
#include
using namespace std;
int main()
{
sets;
s.insert(1);
s.insert(5);
s.insert(7);
s.insert(2);
s.insert(12);
s.insert(10);
auto it = s.lower_bound(15);
cout<< *it <<endl;
return 0;
}
why the output is coming as 6?
Problem in output
Hello, we use lower_bound function when we want to get the first instance of the value from the set or the vector the value that is equal to the given value or just greater than that if it is not present.
Suppose in your set there are some elements like 2 3 4 8 10 22 34
And you use lower_bound function on this set
And when you pass the value 4 then it will get you the pointer whose value is 4 as 4 is present in this.
And when you pass the value 5 then it will get you the pointer whose value is 8 as 5 is not present in this and 8 is the value that we have just greater than 5.
And when we pass 34 it will return the pointer to the value 34.
But think what will happen if we pass the value even greater than the last element that is 34.
So suppose if I pass 37 and as 37 and the value greater than this is not present then it will return the size of the set.
And the same is happening in your case.
As value 15 or greater than 15 is not present here so it is returning the size of the set that is 6.
I hope it is clear to you. In case it is clear to you pls mark it as resolve and provide the rating as well as feedback so that we can improve ourselves.
In case there is still some confusion pls let me know, I will surely try to help you out.
Thanks 
Happy Coding !!
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.