fork(1) download
  1. #include <iostream>
  2. #include <algorithm>
  3.  
  4. int main() {
  5. int arr[] = {0, 2, 3, 5, 5, 6, 8, 8, 8, 9};
  6. auto beg = std::begin(arr);
  7. auto it = std::upper_bound( beg, std::end(arr), 8 );
  8. if( it == beg ) {
  9. std::cout << "no value less than 8 found" << std::endl;
  10. return 0;
  11. }
  12. std::cout << "index is " << std::distance( beg, it ) - 1 << std::endl;
  13. return 0;
  14. }
Success #stdin #stdout 0s 15232KB
stdin
Standard input is empty
stdout
index is 8