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 :
You need to use standard function std::distance
index = std::distance( myvector.begin(), it );
if ( index < myvector.size() )
{
// do something with the vector element with that index
}
Try always to use std::distance
even with random access iterators. This function is available in the new and old C++ Standards.