CHAPTER9-8.cpp
上传用户:fjc899
上传日期:2007-07-03
资源大小:187k
文件大小:1k
- //文件名:CHAPTER9-8.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( )
- {
- multiset <int> ms1;
- multiset <int>::iterator ms1_Iter;
- multiset <int>::reverse_iterator ms1_rIter;
- ms1.insert( 10 );
- ms1.insert( 20 );
- ms1.insert( 30 );
- ms1_rIter = ms1.rbegin( );
- cout << "The first element in the reversed multiset is "
- << *ms1_rIter << "." << endl;
- // begin can be used to start an interation throught a multiset in a forward order
- cout << "The multiset is:";
- for ( ms1_Iter = ms1.begin( ) ; ms1_Iter != ms1.end( ); ms1_Iter++ )
- cout << " " << *ms1_Iter;
- cout << endl;
- // rbegin can be used to start an interation throught a multiset in a reverse order
- cout << "The reversed multiset is:";
- for ( ms1_rIter = ms1.rbegin( ) ; ms1_rIter != ms1.rend( ); ms1_rIter++ )
- cout << " " << *ms1_rIter;
- cout << endl;
- // A multiset element can be erased by dereferencing to its key
- ms1_rIter = ms1.rbegin( );
- ms1.erase ( *ms1_rIter );
- ms1_rIter = ms1.rbegin( );
- cout << "After the erasure, the first element "
- << "in the reversed multiset is "<< *ms1_rIter << "."
- << endl;
- }