set的用法
set<int> st st集合里不含重复数字,所以插入可能错误
pair模板的用法
pair<T1,T2>类型等价于
struct{
T1 first ;
T2 second ;
}
#include<iostream>
#include<cstring>
#include<set>
using namespace std;
int main(){
set<int> st;
int a[10]= {21,3,12,43,54,54,6,78,3,34};
for(int i=0 ; i<10 ;i++)
st.insert(a[i]);
cout << st.size() <<endl; // 8 查看st集合里的个数
set<int>::iterator i; //相当于指针
for(i=st.begin();i != st.end();i++)
cout << *i << "、"; // 3、6、12、21、34、43、54、78、
cout << endl;
/**
pair<set<int>::iterator, bool >
<==>
struct {
set<int>::iterator first;
bool second;
}
**/
pair<set<int>::iterator, bool > result = st.insert(3);
if (! result.second)
cout << *result.first << " alreadly exists. " << endl;
else
cout << *result.first <<" inserted." << endl;
return 0;
}