CHAPTER9-28.cpp
上传用户:fjc899
上传日期:2007-07-03
资源大小:187k
文件大小:1k
- //文件名:CHAPTER9-28.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 multiset<int, less<int> > IntSet;
- IntSet ms1;
- multiset <int> :: const_iterator ms1_RcIter;
- ms1.insert( 10 );
- ms1.insert( 20 );
- ms1.insert( 30 );
- pair <IntSet::const_iterator, IntSet::const_iterator> p1, p2;
- p1 = ms1.equal_range( 20 );
- cout << "The upper bound of the element with "
- << "a key of 20 in the multiset ms1 is: "<< *( p1.second ) << "." << endl;
- cout << "The lower bound of the element with "
- << "a key of 20 in the multiset ms1 is: "<< *( p1.first ) << "." << endl;
- // If no match is found for the key,
- // both elements of the pair return end( )
- if ( ( p2.first == ms1.end( ) ) && ( p2.second == ms1.end( ) ) )
- cout << "The multiset ms1 doesn't have an element "<< "with a key less than 40." << endl;
- else
- cout << "The element of multiset ms1 with a key >= 40 is: "<< *( p1.first ) << "." << endl;
- }