fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. vector<int>v= {2, 3, 7, 10, 11, 11, 25};
  6. auto it= lower_bound(v.begin(),v.end(),8);
  7. int idx = it-v.begin();
  8. auto itr = upper_bound(v.begin(),v.end(),10);
  9. //implementing lower_bound:
  10. // int l=0, h=a.size()-1;
  11. // int k=9;
  12. // int ans = a.size();
  13. int idx2= itr-v.begin();
  14. cout<<" idx is "<<idx<<endl;
  15. cout<<" upper_bound idx is "<<idx2<<endl;
  16. }
Success #stdin #stdout 0.01s 5332KB
stdin
Standard input is empty
stdout
 idx is 3
 upper_bound idx is 4