*
operator follows an iterator to its value
++
++itr
- advance the iterator itr
to the next element and
return the newly advanced iterator
itr++
- remember the iterator itr
, advance itr
to the
next element and return the old itr
==
and !=
- tests if two iterators
refer to the same value or two different values
*itr
- return the value being referenced by the iterator
itr
*
because it can only appear on the
right-hand side of an assignment statement - if itr
is an input
iterator, than
i = *itr;
is correct because *
is being used to read
itr
*itr = i;
is incorrect because *
is being used to write
itr
*itr
- return the location being referenced by the
iterator itr
*
because it can only appear on the
left-hand side of an assignment statement - if itr
is an output
iterator, than
i = *itr;
is incorrect because *
is being used to read
itr
*itr = i;
is correct because *
is being used to write
itr
*itr = *itr + 1;
is correct for a forward iterator
--
- for moving the iterator back to the previous
value
x = *(itr + 5)
+=
and -=
for jumping
around
itr += 5
cnt = end_itr - start_itr - 1;
<
operator - does one iterator refer to a value earlier in the
sequence than another iterator
template <class InputIterator, class T> InputIterator find(InputIterator first, InputIterator last, const T & value)
template <class ForwardIterator1, class ForwardIterator2> ForwardIterator1 search(ForwardIterator1 start1, ForwardIterator1 end1, ForwardIterator2 start2, ForwardIterator2 end2)
(start, end)
,
start
and end
refers to values within the
same container
vector<T>::iterator
vector<T>::const_iterator
begin()
- return an iterator to the first element in a container
vector<int> ivec; vector<int>::iterator start = ivec.begin();
end()
- return an iterator to the last element in a container
vector<int>::iterator five = find(ivec.start(), ivec.end(), 5);
This page last modified on 7 June 2000.