c++ - Returning iterator index on an array search -
i search specific number , have iterator track array element being tested. if number found return index of array number found. here's have far: vector<int>::iterator iterator; find(vector.begin(),vector.end(), num); if(//the number found in search) { return //where number found } i'm not quite sure how sync iterator element of array being tested. appreciate toward solving problem if possible. this should want: std::vector<int> v = {500, 600, 700}; auto = std::find(v.begin(),v.end(), 600); std::size_t pos = - v.begin(); //found(iterator) - begin(iterator) // of course first should check if (it != v.end())