#include <iostream> #include <string> #include <set> using namespace std; int main() { string name[]={"tian","dsp","sp","ti"}; set<string> setname; for (int i=0;i<4;i++) setname.insert(name[i]); set<string>::iterator it; for (it=setname.begin();it!=setname.end();it++) cout<<*it<<" "; it=setname.find("dsp"); cout<<endl; cout<<*it<<endl; setname.erase(it); for (it=setname.begin();it!=setname.end();it++) cout<<*it<<" "; cout<<endl<<setname.size()<<endl<<endl; for (int i=0;i<4;i++) if (setname.count(name[i])>0) cout<<name[i]<<" in set"<<endl; else cout<<name[i]<<" not in set"<<endl; setname.clear(); if (setname.empty()) cout<<"empty"<<endl; system("pause"); return 0; }
转载于:https://www.cnblogs.com/tiandsp/archive/2012/07/26/2610272.html