CHAPTER10-18.cpp
上传用户:fjc899
上传日期:2007-07-03
资源大小:187k
文件大小:2k
- //文件名:CHAPTER10-18.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>::iterator m1_pIter, m2_pIter;
- multimap <int, int> m1, m2;
- typedef pair <int, int> Int_Pair;
- m1.insert ( Int_Pair ( 1, 10 ) );
- m1.insert ( Int_Pair ( 2, 20 ) );
- m1.insert ( Int_Pair ( 3, 30 ) );
- cout << "The original key values of m1 =";
- for ( m1_pIter = m1.begin( ); m1_pIter != m1.end( ); m1_pIter++ )
- cout << " " << m1_pIter -> first;
- cout << "." << endl;
- cout << "The original mapped values of m1 =";
- for ( m1_pIter = m1.begin( ); m1_pIter != m1.end( ); m1_pIter++ )
- cout << " " << m1_pIter -> second;
- cout << "." << endl;
- m1.insert ( Int_Pair ( 1, 10 ) );
- // The hint version of insert
- m1.insert( --m1.end( ), Int_Pair ( 4, 40 ) );
- cout << "After the insertions, the key values of m1 =";
- for ( m1_pIter = m1.begin( ); m1_pIter != m1.end( ); m1_pIter++ )
- cout << " " << m1_pIter -> first;
- cout << "," << " and the mapped values of m1 =";
- for ( m1_pIter = m1.begin( ); m1_pIter != m1.end( ); m1_pIter++ )
- cout << " " << m1_pIter -> second;
- cout << "." << endl;
- m2.insert ( Int_Pair ( 10, 100 ) );
- cout << "After the insertions, the key values of m2 =";
- for ( m2_pIter = m2.begin( ); m2_pIter != m2.end( ); m2_pIter++ )
- cout << " " << m2_pIter -> first;
- cout << "," << endl;
- cout << " and the mapped values of m2 =";
- for ( m2_pIter = m2.begin( ); m2_pIter != m2.end( ); m2_pIter++ )
- cout << " " << m2_pIter -> second;
- cout << "." << endl;
- }