string::cbegin string::cend

const_iterator cbegin() const noexcept;
const_iterator cend() const noexcept;
注:返回常量迭代器,不能修改

#include <iostream>
#include <string>

using namespace std;

int main()
{
string s1("hello");
string::const_iterator it;
it = s1.cbegin();
cout << *it++ << endl;
cout << *it << endl;
//*it = 'a';//wrong read_only
it = s1.cend() - 1;
cout << *it << endl;
//*it = 'a';//wrong read_only
return 0;
}

posted @ 2019-12-23 15:21  MoonXu  阅读(487)  评论(0编辑  收藏  举报