const_interator的用法

来源:互联网 发布:java基础知识体系结构 编辑:程序博客网 时间:2024/05/20 12:51

// 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不能改变所指向的值。


0 0
原创粉丝点击