您的位置:首页 > 编程语言 > C语言/C++

C++STL库之set的用法

2016-10-16 11:50 183 查看
/*set意为集合,是一个内部自动排序不含重复元素的容器*/

#include<stdio.h>
#include<set>
using namespace std;
int main(){
set<int> st;
st.insert(3);
st.insert(3);
st.insert(2);
st.insert(5);
//此处不支持it<st.end()这种写法,因为set不支持*(it+i)的访问方式,set只能通过迭代器访问
for (set<int>::iterator it = st.begin(); it != st.end(); it++){
printf("%d", *it);
}
}


输出结果如下:

235
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: