Used for traversal access by some special classes, similar to a pointer.

The following uses vector[vector] as an example:

How to create an iterator:

list<int>::iterator it;

Common operations, iterator traversal:

for(it = l.begin(); it != l.end(); it++)

Among them, l is a list type variable. First, the iterator is equal to the first address of l and then added to the last address of l.
PS: In most STL, the tail address points to an empty element, so use! =

Access the iterator:

print(%d, *it);

This means outputting the contents of the list. The iterator is similar to a pointer. To usePerform content retrieval operations
PS: Because
The operation level is low, so most of the time you need to add parentheses like (*it) –> first.

Completely traverse the output code

#include <cstdio>
#include <list>
using namespce std;

int main() {
    list<int> l;
    //省略读入代码
    list<int>::iterator it;
    for(it = l.begin(); it != l.end(); it++)
        printf("%d\n", *it)
    return 0;
}

Post Reply