您当前的位置: 首页 >  c++
  • 0浏览

    0关注

    1477博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

C++ begin( ) cbegin( ) end() cend()区别

软件工程小施同学 发布时间:2021-10-12 10:25:03 ,浏览量:0

1.iterator,const_iterator作用:遍历容器内的元素,并访问这些元素的值。iterator可以改元素值,但const_iterator不可改。跟C的指针有点像。 2.const_iterator 对象可以用于const vector 或非 const vector,它自身的值可以改(可以指向其他元素),但不能改写其指向的元素值。 3.cbegin()和cend()是C++11新增的,它们返回一个const的迭代器,不能用于修改元素。

#include 
#include 

using namespace std;

int main()
{
	
    // cbegin/cend(c++11): Returns a const_iterator pointing to the first element in the container/
	// Returns a const_iterator pointing to the past-the-end element in the container
	std::set myset = { 50, 20, 60, 10, 25 };
 
	std::cout             
关注
打赏
1665320866
查看更多评论
0.0397s