// string::cbegin/cend
#include <iostream>
#include <string>
int main ()
{
std::string str ("Lorem ipsum");
for (auto it=str.cbegin(); it!=str.cend(); ++it)
std::cout << *it;
std::cout << '\n';
return 0;
}
A const_iterator is an iterator that points to const content. This iterator can be increased and decreased (unless it is itself also const), just like the iterator returned by string::begin , but it cannot be used to modify the contents it points to, even if the string object is not itself const.
注意的是:const_iterator不能改变所指向的值。