C++中Set的使用
/* #include <string> // 使用 string 类时须包含这个文件 #include <iostream> // 这个就加上去吧。c++的输入和输出。 using namespace std; // 这个不能忘记了 String 类的输入和输出要用cin和cout,否则就爆栈错了 */#include <iostream> #include <set> #include <string> using namespace std;set<string> ::iterator it; void print(set<string> iset) {for (it = iset.begin();it != iset.end();it++){cout << *it;} } //函数还是能包装的。set也可以当做参数传入 int main() {set<string> iset;iset.insert("1");iset.insert("2");iset.insert("3");/* 两种遍历set<string> ::iterator it;for (it = iset.begin();it != iset.end();it++){cout << *it;}set<string> ::reverse_iterator rit;for (rit = iset.rbegin();rit != iset.rend();rit++){cout << *rit;}迭代器和函数一一对应的。iterator -> begin endreverse_iterator -> rbegin rend*//*貌似只能删除键值。iset.erase("2");print(iset);*//* 返回的是迭代器。it = iset.find("1");cout << *it;*/}
my own code
It's beyond my imagination,the Iterator appears in the C++!
In my view,the Iterator only appears int the Java.(I'm so shortsighted)
there isn't any doubt that the Iterator is a powerful tool to traverse Collection.
just as you see,you can easily use a simple circle to implement traversal.
There is another point worth mentioning,the function "find" return Iterator.
according to my experience.the Iterator is actually a point.
you can try to output the value of Iterator.Which is always obeyond the range of Integer.
It appears more evident that using the '*' to get the actual value of the Iterator.
转载于:https://www.cnblogs.com/Milkor/p/4397300.html
C++中Set的使用相关推荐
- GNU Make 使用手册(于凤昌中译版)
GNU Make 使用手册(中译版) 翻译:于凤昌 GNU make Version 3.79 April 2000 Richard M. Stallman and Roland McGrath 1 ...
- 面试:第十二章:所有总结
Java基础 java基本类型哪些,所占字节 byte :1个字节 short :2个字节 char :2个字节 int :4个字节 long :8个字节 float :4个字节 double :8个 ...
- linux内核分析(转自某位大哥网上的笔记)
启动 当PC启动时,Intel系列的CPU首先进入的是实模式,并开始执行位于地址0xFFFF0处的代码,也就是ROM-BIOS起始位置的代码.BIOS先进行一系列的系统自检,然后初始化位于地址0的中断 ...
- golang通过RSA算法生成token,go从配置文件中注入密钥文件,go从文件中读取密钥文件,go RSA算法下token生成与解析;go java token共用
RSA算法 token生成与解析 本文演示两种方式,一种是把密钥文件放在配置文件中,一种是把密钥文件本身放入项目或者容器中. 下面两种的区别在于私钥公钥的初始化, init方法,需要哪种取哪种. 通过 ...
- 总结一下在使用某里云服务器的过程中出现过的一些问题
此文总结在使用阿里云的过程中出现过的问题 想起来就记录一下 本人为言行负责! 海内选择腾讯华为,共勉! k8s不同命名空间的配置文件串掉了 k8s集群服务器购买上后,无法使用外网.连续购买了4台然 ...
- Kubernetes 中 设置pod不部署在同一台节点上
在k8s中,节点的调度主要由亲和性和污点来进行控制的. 而在亲和性部分由分为了节点亲和性和节点反亲和性. 节点亲和性是指在pod部署时,尽量(软策略)或者必须满足(硬策略)部署在某些节点上. ...
- 在Dockerfile中设置G1垃圾回收器参数
在Dockerfile中设置G1垃圾回收器参数 ENV JAVA_OPTS="\ -server \ -XX:SurvivorRatio=8 \ -XX:+DisableExplicitGC ...
- 在kotlin companion object中读取Bean,注入Bean对象
在kotlin companion object中读取Bean,注入Bean对象 在使用kotlin时,或多或少地会使用到一些公共组件,如 http. mongo. redis相关的组件. 使用组 ...
- 在k8s中使用gradle构建java web项目镜像Dockerfile
在k8s中使用gradle构建java web项目镜像Dockerfile FROM gradle:6-jdk8 AS build COPY --chown=gradle:gradle . /home ...
- 数据库中自定义排序规则,Mysql中自定义字段排序规则,Oracle中自定义字段排序规则,decode函数的用法,field函数的用法
数据库中自定义排序 场景:有一张banner表,表中有一个status字段,有0, 1, 2三个状态位,我想要 1,0,2的自定义排序(这里是重点),然后再进行之上对sequence字段进行二次排序( ...
最新文章
- 编解码器架构中的桥(bridge)指什么
- 乐山市计算机学校坑不坑,据说这个学校很乱。
- 中国工程院院士:我这里博士生的待遇,不如能干的工人高!
- iOS 仿看了吗应用、指南针测网速等常用工具、自定义弹出视图框架、图片裁剪、内容扩展等源码...
- 一个后端开发人员的node.js学习笔记(一)安装与第一个服务器
- 想转行做web前端工程师,必学这6大技能!你都知道吗?
- 【BZOJ10561862】【codevs1985】排名系统,Splay+trie树
- altium designer(AD13)隐藏敷铜的方法
- java 获取已有字体,java获取本机所有可用字体
- 校招----吉比特一面面经
- Discuz大气游戏风格模板/仿lol英雄联盟游戏DZ游戏模板GBK
- 如何使用 mocha 和 sinon 集成单元测试--单元测试示例及分析(上)
- 数据可视化笔记之视觉感知认知
- 关于windows系统中txt文档的换行符\r\n
- ssm基于微信小程序的电影影评交流平台系统 uni-app
- 完全k叉树(CCPC-Wannafly Comet OJ 夏季欢乐赛(2019) A)
- MacBookPro硬盘升级记
- 快速有效地封杀—巧利用Iris来查找蠕虫病毒(转)
- vue scoped关键字
- 小心这些没有硝烟的鸦片软件