C++ STL中set的一些用法
2008-08-07 09:12
603 查看
C++ STL中set的一些用法
#include <iostream> #include <set> #include<algorithm> using namespace std; int main() { int i; char b[10]; for( i = 0; i < 10; i++ )b[i] = i+'a'; set<char>a(b,b+10); set<char>::iterator p; for( p = a.begin(); p != a.end(); p++ ) { cout << *p << " "; } cout << endl << endl; cout << "count('a') = " << a.count('a') << endl << endl; set<char>c; cout << "c.empty = " << c.empty() << endl << endl; pair<set<char>::iterator, set<char>::iterator>s; pair<set<char>::iterator,bool>d; d = a.insert('e'); cout << "d.second = " << d.second << endl; s = a.equal_range('e'); for( p = s.first; p != s.second; p++ )cout << *p << " "; cout << endl; a.erase('e'); for( p = a.begin(); p != a.end(); p++ ) { cout << *p << " "; } cout << endl << endl; p = a.find('c'); cout << *p << endl; p = a.lower_bound('e'); for( ; p != a.end(); p++ )cout << *p << " "; cout << endl << endl; set<char>::reverse_iterator q; for( q = a.rbegin(); q != a.rend(); q++ )cout << *q << " "; cout << endl << endl; set<char>r; for( i = 0; i < 5; i++ )r.insert(i+'u'); for( p = r.begin(); p != r.end(); p++ )cout << *p << " "; cout << endl << endl; r.swap(a); for( p = r.begin(); p != r.end(); p++ )cout << *p << " "; cout << endl << endl; for( p = a.begin(); p != a.end(); p++ )cout << *p << " "; cout << endl << endl; return 0; } |
相关文章推荐
- c++ stl容器set成员函数介绍及set集合插入,遍历等用法举例
- C++ STL set集合容器常用用法
- C++之STL中set的用法 PAT L2-005 集合相似度
- C++STL库之set的用法
- C++ STL 算法 --- 你可能不知道的一些用法
- C++ STL set::find的用法
- C++ STL 中map的一些用法
- C++之STL中set的用法总结
- c++ stl容器set成员函数介绍及set集合插入,遍历等用法举例
- [C++::STL]之set的用法
- C++ 标准模板库STL中set用法介绍
- c++ stl容器set成员函数介绍及set集合插入,遍历等用法举例
- C++ STL 算法 --- 你可能不知道的一些用法
- STL_set用法
- c++之stl中的stack用法总结
- [自考]C++中一些特殊用法
- C++中的STL中map用法详解
- C++中STL用法总结
- C++的STL中的map用法详解
- C++ STL <map> 用法简介