C++ 的STL 标准模板库提供了强大的功能,以前一直在CD的怀抱,所以没怎么用过,现在想进一步接触。多了解,看看日后或许会使用上...
- #include <iostream>
- #include <string>
- #include <set>
- #include <stdlib.h>
- using namespace std;
- int main(int agrc,char *argv[]){
- string alias[]={"xtramus","usrp","nutap","rm881"};
- set<string> product_alias;//
- for(int i=0;i<4;i++){
- product_alias.insert(alias[i]);
- }
- set<string>::const_iterator it;
- for(it=product_alias.begin();it!=product_alias.end();it++){
- cout<<*it<<" ";
- }
- it=product_alias.find("usrp");
- cout<<endl;
- cout<<*it<<endl;
- product_alias.erase(it);
- product_alias.insert(product_alias.end(),"");
- for(it=product_alias.begin();it!=product_alias.end();it++){
- cout<<*it<<" ";
-
- }
- cout<<endl<<product_alias.size()<<endl<<endl;
- for(int i=0;i<4;i++){
- if(product_alias.count(alias[i])>0)
- cout<<alias[i]<<" in set"<<endl;
- else
- cout<<alias[i]<<" not in set"<<endl;
- }
- product_alias.clear();
- if(product_alias.empty())
- cout<<"empty"<<endl;
- pause();
- //system("pause");
- return 0;
-
-
- }
将上面代码编译运行,得出下图结果比起C来,得来不费功夫的感觉!
阅读(487) | 评论(0) | 转发(0) |