CHAPTER9-10.cpp
上传用户:fjc899
上传日期:2007-07-03
资源大小:187k
文件大小:1k
- //文件名:CHAPTER9-10.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;
- multiset <int>::const_reverse_iterator ms1_crIter;
- ms1.insert( 10 );
- ms1.insert( 20 );
- ms1.insert( 30 );
- ms1_rIter = ms1.rend( ) ;
- ms1_rIter--;
- cout << "The last element in the reversed multiset is "
- << *ms1_rIter << "." << endl;
- // end can be used to terminate 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;
- // rend can be used to terminate 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;
- ms1_rIter = ms1.rend( );
- ms1_rIter--;
- ms1.erase ( *ms1_rIter );
- ms1_rIter = ms1.rend( );
- cout << "After the erasure, the last element in the "
- << "reversed multiset is " << *ms1_rIter << "." << endl;
- }