   Vectors and iterators
  Hello there,Im trying to display the contents of a vector using an iterator, thats all fine but I want to index the output with the number of the element.Here is my code:   for (iter = names.begin(); iter != names.end(); iter++)   { cout << iter << *iter << endl;   }It seems iter by its self cannot be sent to cout.  So basically im asking whats the best way to output the current element number.  I could use a extra var but im trying to do it as cleanly and simply as possible.Could anyone advise me on this? :)   
  The general answer is to use std::distance(names.begin(), iter). In practice, for random-access iterators, you can use the equivalent iter - names.begin().   ;for ( n=0, iter=names.begin() ; iter != names.end() ; ++n, ++iter ){    cout << n << *iter << endl;}(Note:  You want to prefer prefix increments when possible)If you don't mind hardcoding your loop to work only with random access containers:for ( iter=names.begin() ; iter != names.end() ; ++iter ){    cout << (iter-names.begin()) << *iter << endl;};  Thanks for the unbelievable response time!Perfect soloution, thats exactly the kind om simplicity i was looking for!Thanks people   