What do you need the iterator for? If it is for iterating from
back to front, you can use the reverse iterators (rbegin
,
rend
). If it is a function which expects an iterator (for
example, because you want it to iterate through all but the last
element), then you can use end() - 1
on a vector. This will
only work on random access iterators, however; for other types,
you will need std::prev
(if you've got C++11) or the
equivalent from your toolkit (pre C++11):
template <typename BidirectionalIterator>
BidirectionalIterator
prev( BidirectionalIterator it )
{
-- it;
return it;
}
(If you don't have it already, and aren't using C++11, add it to
your toolkit.)