Visual C++ 6 Unleashed

Visual C++ 6 Unleashed

By MICKEY WILLIAMS and David Bennett

Iterators

Iterators provide access to containers in a pointer-like manner. You use them to access the elements in a container. The three major classes of iterators are forward, bidirectional, and random access. A forward iterator provides for one-directional forward movement only, which can be accomplished using ++. Bidirectional iterators can traverse in both directions, using ++ and ––. A random-access iterator can move both forward and backward, and jump to an arbitrary position.

Also, two other categories of iterators exist: input iterators and output iterators. The input iterator can be an intermediate to an input device to read sequential data items and place them into a container. An output iterator can be an intermediate to an output device and write the elements from a container to the device.

Note that the values for the forward, bidirectional, and random-access iterators can be stored in memory for later retrieval. The values for the input iterator and the output iterator cannot be stored, because they would be referencing input and output devices respectively, where the values that are received would not apply.

Share ThisShare This

Informit Network