fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4.  
  5. int main()
  6. {
  7. std::vector<int> v = {3,4,5,6,7,8,9};
  8.  
  9. int pos = -1;
  10. std::vector<int>::iterator it;
  11.  
  12. if((it = std::find(v.begin(), v.end(), 6)) != v.end())
  13. pos = it - v.begin();
  14.  
  15. std::cout << "6 is at pos " << pos << std::endl;
  16. }
Success #stdin #stdout 0s 2984KB
stdin
Standard input is empty
stdout
6 is at pos 3