A const iterator, as the name implies, is an iterator that cannot be changed, and is a constant whose nature is determined by the Const. Let's say we define a const iterator like this.
vector<int> VV (9); const vector<int
is incorrect when the following statement appears in the program
++iter;
The reason for this is that ITER is a constant and therefore cannot be changed. In other words, ITER can only point to the one element of the VV, and cannot point to other elements.
But such statements are correct:
ten;
Because although ITER cannot point to other elements, the value of the first element it points to can be changed.
And for Const_iterator, the opposite is the case. For example, we define this.
vector<int> VV (9); Vector<int>:: Const_iterator iter;
A const_iterator iterator is defined. This iterator can be added on its own, but the element it points to cannot be changed. For example
for (iter = Vv.begin (); ITER! = Vv.end (); +iter) {<< *iter << endl; }
This is true, that is, the value of ITER itself can be changed. But
for (iter = Vv.begin (); ITER! = Vv.end (); + iter) {0 ; }
This is not true because the Const_iterator iterator cannot change the value of the element it points to.
C + +------The difference between const iterators and const_iterator