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