1.set.insert(elem);     //在容器中插入元素。

2.set.begin();         //返回容器中第一个数据的迭代器。

3.set.end();          //返回容器中最后一个数据之后的迭代器。

4.set.rbegin();        //返回容器中倒数第一个元素的迭代器。

5.set.rend();         //返回容器中倒数最后一个元素的后面的迭代器。

使用方法如下:

 1 #include <iostream>
2 #include <set>
3
4 using namespace std;
5
6 int main()
7 {
8 set<int> setInt;
9
10 //在容器中插入元素
11 setInt.insert(1);
12 setInt.insert(2);
13 setInt.insert(3);
14 setInt.insert(4);
15 setInt.insert(5);
16
17 //返回容器中第一个数据的迭代器赋值给 it,如果不等于最后一个数据的迭代器便 it++
18 for (set<int>::iterator it = setInt.begin(); it != setInt.end(); it++)
19 {
20 cout << *it << endl;
21 }
22
23 cout << endl;
24
25 //返回容器中倒数第一个元素的迭代器赋值给 it,如果不等于倒数最后一个数据的迭代器便 it++
26 //这里需要注意一点,rbegin 的返回类型应该为 reverse_iterator ,并且 reverse_iterator 的++操作将会是往前移动的操作
27 for (set<int>::reverse_iterator it = setInt.rbegin(); it != setInt.rend(); it++)
28 {
29 cout << *it << endl;
30 }
31
32 return 0;
33 }

打印结果:

这里需要注意 rbegin 的返回值类型为 reverse_iterator

1     _NODISCARD reverse_iterator rbegin() noexcept
2 {
3 return reverse_iterator(end());
4 }

========================================================================================================================================

最新文章

  1. centos7 开启防火墙端口 firewalld
  2. 手写json
  3. Linux环境变量配置
  4. selenium下拉框选择
  5. django中request对象详解(转载)
  6. OS X EI Capitan安装mcrypt
  7. 修改Oracle 10g Express Edition默认的8080端口
  8. 卸载sqlserver数据库参考
  9. 用composer安装 Laravel | Laravel需要的环境配置
  10. PyQt4 的事件与信号 -- 发射信号
  11. SSH概念及常用操作汇总
  12. windows server 简化设置
  13. 【js】关于this指针-理解call、apply、bind
  14. JavaScript中判断整字类型最简洁的实现方法
  15. mysql 一张表的多个字段关联另外一张表
  16. js 实现复制粘贴时注意方法中需要两次点击实现的bug
  17. CSS3注意点
  18. POJ 1087 A Plug for UNIX / HDU 1526 A Plug for UNIX / ZOJ 1157 A Plug for UNIX / UVA 753 A Plug for UNIX / UVAlive 5418 A Plug for UNIX / SCU 1671 A Plug for UNIX (网络流)
  19. python之函数用法endswith()
  20. 深入浅出MFC——MFC骨干程序(四)

热门文章

  1. Jrebel &amp; Xrebel 在线激活方法 (亲测可用)
  2. webpack : 无法加载文件 C:\Users\Eileen\AppData\Roaming\npm\webpack.ps1,因为在此系统上禁止运行脚本
  3. [代码审计]:PhpMyWind储存型XSS漏洞(CVE-2017-12984)
  4. python 中 try...finally... 的优雅实现
  5. {&quot;non_field_errors&quot;:[&quot;Unable to log in with provided credentials.&quot;]}% 无法使用提供的凭据登录
  6. Luogu P2656 采蘑菇
  7. [笔记] dumpsys meminfo数据与smaps文件对应关系
  8. Kafka源码环境搭建
  9. 手把手教你使用Vue/React/Angular三大框架开发Pagination分页组件
  10. 这些鲜为人知的前端冷知识,你都GET了吗?