The two are very different, but they are not very easy to understand, and they feel that the explanations are also various detours. Let's talk about my own understanding.
The const iterator, as its name implies, is a constant that cannot be changed. Its nature is determined by const. For example, we define a const iterator.
Vector <int> vv (10, 9 );
Const vector <int >:: iterator iter = vv. begin ();
It is incorrect when such a statement appears in the program.
++ Iter;
The reason is that iter is a constant, so it cannot be changed. In other words, iter can only point to one element of vv and cannot point to other elements.
However, this statement is correct:
× Iter = 10;
Although iter cannot point to other elements, the value of the first element to which it points can be changed.
For const_iterator, the opposite is true. For example, we define
Vector <int> vv (10, 9 );
Vector <int>: const_iterator iter;
A const_iterator iterator is defined. This iterator can be added by itself, but the elements it points to cannot be changed. For example
For (iter = vv. begin (); iter! = Vv. end (); ++ iter ){
Cout <* iter <endl;
}
This is correct, that is, the iter value can be changed. However
For (iter = vv. begin (); iter! = Vv. end (); ++ iter ){
* Iter = 0;
}
This is wrong, because the const_iterator iterator cannot change the value of the element to which it points.