STL中set的使用
2017-02-04 22:45
148 查看
#include <cmath> #include <cstdio> #include <algorithm> #include <iostream> #include <set> #include <iterator> using namespace std; int main() { typedef set<double > double_set;//等价于typedef set<double,less<double> > double_set; const int SIZE=5; double a[SIZE]={2.1, 4.2, 9.5, 2.1, 3.7}; double_set doubleSet(a,a+SIZE); ostream_iterator<double> output(cout," "); cout<<"1)"; copy(doubleSet.begin(),doubleSet.end(),output); cout<<endl; pair<double_set::const_iterator,bool> p; p=doubleSet.insert(9.5); //insert()函数返回值是一个pair对象,其first是被插入元素的迭代器, //second代表是否成功插入了 //因为插入的是9.5,而9.5 set容器早已含有,所以插入不成功 if(p.second) cout<<"2)"<<*(p.first)<<" inserted"<<endl; else cout<<"2)"<<*p.first<<" not inserted"<<endl; //*p.first等价于*(p.first) return 0; }
相关文章推荐
- stl中的set_difference的使用
- 高效的使用stl::map和std::set
- STL之set使用方法小结
- STL之set使用方法小结
- STL中list,vector,deque,map,set区别、联系和使用场景
- STL容器使用DEMO-set
- STL优先级队列(priority_queue)和集合(set)的使用
- STL中list,vector,deque,map,set区别、联系和使用场景
- STL之set使用方法小结
- C++中防止STL中迭代器失效__map/set等关联容器vector/list/deque等序列容器_如何防止迭代器失效_即erase()的使用
- STL -------set 使用总结
- 转贴:STL之set使用方法小结
- C++中使用stl的set和hash_set
- STL之set使用方法小结
- STL之set使用方法小结
- STL------list、set、map的简单使用
- STL之set使用方法小结
- STL中list,vector,deque,map,set区别、联系和使用场景
- C++ STL入门教程(6)——set(集合)的使用(附完整程序代码)
- STL之set使用方法小结