An iterator (iterator) is a pointer type, and also points to the Const pointer itself (address) and the value indicated by the const pointer, in two cases;
But the writing and const built-in pointers are different;
char * const is equivalent to const container<>::iterator; You can modify the value that the pointer refers to, but you cannot modify the pointer's address;
const char * equivalent to container<>::const_iterator; You can modify the pointer address, but you cannot modify the value indicated by the pointer;
Note The code example, two const and iterators;
Code:
* * * * effectivecpp.cpp * * Created on:2013.11.13 * author:caroline
* */*eclipse CDT; GCC 4.7.1*/
#include <iostream>
#include <vector>
int main (void) {
std::vector< Int> IV = {1, 2, 3, 4, 5};
Const AUTO IT = Iv.begin (); The const iterator is equivalent to t* const, and the pointer itself (address) is fixed;
Std::cout << "*it =" << *it << Std::endl;
++it; Error
*it = ten;
Std::cout << "*it =" << *it << Std::endl;
IV = {1, 2, 3, 4, 5};
Auto CIT = Iv.cbegin (); Cbegin, equivalent to Const_iterator, the finger of the pointer is fixed;
Std::vector<int>::const_iterator cit = Iv.begin ();
Std::cout << "*cit =" << *cit << Std::endl;
++cit;
*cit = 10; Error
std::cout << "*cit =" << *cit << Std::endl;
return 0;
}
Author: csdn Blog spike_king
More Wonderful content: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/cplus/