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
关注
打赏
热门博文
- DevOps实践教程 华为云 系列教程2021 合集
- ❤️Python Django网站开发 2021年最新版教程 合集❤️
- ❤️java多线程并发编程入门 教程合集❤️
- ❤️区块链Hyperledger Fabric 老版本 1.1.0 快速部署安装 教程合集❤️
- ❤️Docker教程小白实操入门 教程合集❤️
- ❤️微信小程序 云开发 教程合集(视频+图文)免费❤️
- C++ boost::asio::io_service创建线程池thread_group简单实例
- C++ error: ‘shared_ptr’ was not declared in this scope
- git 代码回滚回退到指定版本 并 提交
- C++ 得到map中最后一个元素