次の方法で共有


<iterator>

Defines the iterator primitives, predefined iterators and stream iterators, as well as several supporting templates. The predefined iterators include insert and reverse adaptors. There are three classes of insert iterator adaptors: front, back, and general. They provide insert semantics rather than the overwrite semantics that the container member function iterators provide.

For a list of all members of this header, see <iterator> Members.

#include <iterator>

Remarks

Iterators are a generalization of pointers, abstracting from their requirements in a way that allows a C++ program to work with different data structures in a uniform manner. Iterators act as intermediaries between containers and generic algorithms. Instead of operating on specific data types, algorithms are defined to operate on a range specified by a type of iterator. Any data structure that satisfies the requirements of the iterator may then be operated on by the algorithm. There are five types or categories of iterator, each with its own set of requirements and resulting functionality:

  • Output: forward moving, may store but not retrieve values, provided by ostream and inserter.

  • Input: forward moving, may retrieve but not store values, provided by istream.

  • Forward: forward moving, may store and retrieve values.

  • Bidirectional: forward and backward moving, may store and retrieve values, provided by list, set, multiset, map, and multimap.

  • Random access: elements accessed in any order, may store and retrieve values, provided by vector, deque, string, and array.

Iterators that have greater requirements and so more powerful access to elements may be used in place of iterators with fewer requirements. For example, if a forward iterator is called for, then a random-access iterator may used instead.

See Also

Reference

Thread Safety in the Standard C++ Library

Standard Template Library

Other Resources

<iterator> Members

Header Files