DSP

STL练习程序(set...)

2019-07-13 15:35发布

#include #include <string> #include <set> using namespace std; int main() { string name[]={"tian","dsp","su","chu"}; 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; for (int i=0;i<4;i++) if (setname.count(name[i])>0) cout<" in set"<<endl; else cout<" not in set"<<endl; setname.clear(); if (setname.empty()) cout<<"empty"<<endl; system("pause"); return 0; }