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