fork download
  1. // C++ code to demonstrate the working of lower_bound()
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4.  
  5. // Driver's code
  6. int main()
  7. {
  8. pair<int, int> v[10];
  9. for(int i=0;i<10;i++){
  10. v[i] = (make_pair(i,i));
  11. }
  12. for(int i=0;i<10;i++){
  13. cout<<v[i].first<<" "<<v[i].second<<endl;
  14. }
  15.  
  16. int index = lower_bound(v, v+10, make_pair(21,21),
  17. [](const pair<int,int>& lhs, const pair<int,int>& rhs){ return lhs.first < rhs.first; }) - v;
  18.  
  19. cout<<index<<endl;
  20. }
  21.  
Success #stdin #stdout 0.01s 5472KB
stdin
Standard input is empty
stdout
0 0
1 1
2 2
3 3
4 4
5 5
6 6
7 7
8 8
9 9
10