STL之set模板

#include<iostream>
#include<set>
using namespace std;
int main(){
    
    
	set<int> st;
	st.insert(5);//5
	int x=1;
	st.insert(x);//1,5
	st.insert(1);//1,5
	st.insert(2);
	st.insert(3);//1,2,3,5
	if(st.count(1))//统计1的次数,仅为1或0 
		st.insert(1);//删除 
	cout<<st.size()<<endl;//元素的数量 
	for(set<int>::iterator it=st.begin();
		it!=st.end();it++)
		cout<<(*it)<<" ";//集合的遍历 ,输出各个集合的值
	st.clear();//清空集合
	return 0;
} 	 

猜你喜欢

转载自blog.csdn.net/m0_51794965/article/details/112831849