I am looking for an element in a C++ vector, and when I find it, I want to get found element\'s index in a numerical form(integer, float).
My naive attempt is this :
If you want the index of the found element, then that's the distance from the start of the sequence:
index = it - myvector.begin();
or, since C++11,
index = std::distance(myvector.begin(), it);
which will work with any forward iterator type, not just random-access ones like those from a vector.