You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
952 B

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#include<bits/stdc++.h>
using namespace std;
/*
知识点内容STL set详解
关于set必须说明的是set关联式容器。 set作为一个容器也是用来存储同一数据类型的数据类型
并且能从一个数据集合中取出数据在set中每个元素的值都唯一而且系统能根据元素的值自动进行排序。
文档内容参考:
https://www.cnblogs.com/aiguona/p/7231399.html
* */
int main() {
int i;
set<int> set1;
for (i = 0; i < 10; ++i)
set1.insert(i);
//迭代器
set<int>::iterator it;
for (it = set1.begin(); it != set1.end(); it++)
cout << *it << "\t";
cout << endl;
//把3插入到set1中,插入成功则set1.insert(3).second返回1否则返回0.
set1.erase(5);
if (set1.insert(3).second)
cout << "set insert success";
else
cout << "set insert failed";
cout << endl;
//迭代输出
set<int>::iterator itr;
for (itr = set1.begin(); itr != set1.end(); itr++)
cout << *itr << "\t";
set1.clear();
return 0;
}