CHAPTER9-1.cpp
上传用户:fjc899
上传日期:2007-07-03
资源大小:187k
文件大小:2k
- //文件名:CHAPTER9-1.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>::iterator s1_Iter, s2_Iter, s3_Iter, s4_Iter, s5_Iter, s6_Iter;
- // Create an empty set s0 of key type integer
- set <int> s0;
- // Create an empty set s1 with the key comparison
- // function of less than, then insert 4 elements
- set <int, less<int> > s1;
- s1.insert( 10 );
- s1.insert( 20 );
- s1.insert( 30 );
- s1.insert( 40 );
- // Create an empty set s2 with the key comparison
- // function of geater than, then insert 2 elements
- set <int, greater<int> > s2;
- s2.insert(10);
- s2.insert(20);
- // Create a set s3 with the
- // allocator of set s1
- set <int>::allocator_type s1_Alloc;
- s1_Alloc = s1.get_allocator( );
- set <int> s3( less<int>( ), s1_Alloc );
- s3.insert( 30 );
- // Create a copy, set s4, of set s1
- set <int> s4( s1 );
- // Create a set s5 by copying the range s1[_First, _Last)
- set <int>::const_iterator s1_bcIter, s1_ecIter;
- s1_bcIter = s1.begin( );
- s1_ecIter = s1.begin( );
- s1_ecIter++;
- s1_ecIter++;
- // set <int> s5( s1_bcIter, s1_ecIter );
- // Create a set s6 by copying the range s4[_First, _Last)
- // and with the allocator of set s2
- set <int>::allocator_type s2_Alloc;
- s2_Alloc = s2.get_allocator( );
- // set <int> s6( s4.begin( ), ++s4.begin( ), less<int>( ), s2_Alloc );
- cout << "s1 =";
- for ( s1_Iter = s1.begin( ); s1_Iter != s1.end( ); s1_Iter++ )
- cout << " " << *s1_Iter;
- cout << endl;
- cout << "s2 = " << *s2.begin( ) << " " << *++s2.begin( ) << endl;
- cout << "s3 =";
- for ( s3_Iter = s3.begin( ); s3_Iter != s3.end( ); s3_Iter++ )
- cout << " " << *s3_Iter;
- cout << endl;
- cout << "s4 =";
- for ( s4_Iter = s4.begin( ); s4_Iter != s4.end( ); s4_Iter++ )
- cout << " " << *s4_Iter;
- cout << endl;
- /* cout << "s5 =";
- for ( s5_Iter = s5.begin( ); s5_Iter != s5.end( ); s5_Iter++ )
- cout << " " << *s5_Iter;
- cout << endl;
- cout << "s6 =";
- for ( s6_Iter = s6.begin( ); s6_Iter != s6.end( ); s6_Iter++ )
- cout << " " << *s6_Iter;
- cout << endl;*/
- return 0;
- }