CHAPTER10-24.cpp
上传用户:fjc899
上传日期:2007-07-03
资源大小:187k
文件大小:1k
- //文件名:CHAPTER10-24.cpp
- #include <map>
- #include <iostream>
- #if _MSC_VER > 1020 // if VC++ version is > 4.2
- using namespace std; // std c++ libs implemented in std
- #endif
- void main( )
- {
- multimap <int, int> m1, m2, m3;
- multimap <int, int>::iterator m1_Iter;
- typedef pair <int, int> Int_Pair;
- m1.insert ( Int_Pair ( 1, 10 ) );
- m1.insert ( Int_Pair ( 2, 20 ) );
- m1.insert ( Int_Pair ( 3, 30 ) );
- m2.insert ( Int_Pair ( 10, 100 ) );
- m2.insert ( Int_Pair ( 20, 200 ) );
- m3.insert ( Int_Pair ( 30, 300 ) );
- cout << "The original multimap m1 is:";
- for ( m1_Iter = m1.begin( ); m1_Iter != m1.end( ); m1_Iter++ ) cout << " " << m1_Iter -> second;
- cout << "." << endl;
- // This is the member function version of swap
- m1.swap( m2 );
- cout << "After swapping with m2, multimap m1 is:";
- for ( m1_Iter = m1.begin( ); m1_Iter != m1.end( ); m1_Iter++ ) cout << " " << m1_Iter -> second;
- cout << "." << endl;
- // This is the specialized template version of swap
- swap( m1, m3 );
- cout << "After swapping with m3, multimap m1 is:";
- for ( m1_Iter = m1.begin( ); m1_Iter != m1.end( ); m1_Iter++ )cout << " " << m1_Iter -> second;
- cout << "." << endl;
- }