How to convert vector iterator to int in C++

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.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)