CHAPTER9-27.cpp
上传用户:fjc899
上传日期:2007-07-03
资源大小:187k
文件大小:1k
- //文件名:CHAPTER9-27.cpp
- #include <set>
- #include <iostream>
- #if _MSC_VER > 1020 // if VC++ version is > 4.2
- using namespace std; // std c++ libs implemented in std
- #endif
- int main( )
- {
- typedef set<int, less< int > > IntSet;
- IntSet s1;
- set <int, less< int > > :: const_iterator s1_RcIter;
- s1.insert( 10 );
- s1.insert( 20 );
- s1.insert( 30 );
- pair <IntSet::const_iterator, IntSet::const_iterator> p1, p2;
- p1 = s1.equal_range( 20 );
- cout << "The upper bound of the element with "
- << "a key of 20 in the set s1 is: "<< *(p1.second) << "." << endl;
- cout << "The lower bound of the element with "
- << "a key of 20 in the set s1 is: "<< *(p1.first) << "." << endl;
- // If no match is found for the key, both elements of the pair return end( )
- if ( ( p2.first == s1.end( ) ) && ( p2.second == s1.end( ) ) )
- cout << "The set s1 doesn't have an element "<< "with a key less than 40." << endl;
- else
- cout << "The element of set s1 with a key >= 40 is: "<< *(p1.first) << "." << endl;
- }