📄 chapter10-2.cpp
字号:
//文件名:CHAPTER10-2.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( )
{
typedef pair <int, int> Int_Pair;
multimap <int, int>::iterator m1_Iter, m3_Iter, m4_Iter, m5_Iter, m6_Iter;
multimap <int, int, greater<int> >::iterator m2_Iter;
// Create an empty multimap m0 of key type integer
multimap <int, int> m0;
// Create an empty multimap m1 with the key comparison
// function of less than, then insert 4 elements
multimap <int, int, less<int> > m1;
m1.insert( Int_Pair( 1, 10 ) );
m1.insert( Int_Pair( 2, 20 ) );
m1.insert( Int_Pair( 3, 30 ) );
m1.insert( Int_Pair( 4, 40 ) );
// Create an empty multimap m2 with the key comparison
// function of geater than, then insert 2 elements
multimap <int, int, greater<int> > m2;
m2.insert( Int_Pair( 1, 10 ) );
m2.insert( Int_Pair( 2, 20 ) );
// Create a multimap m3 with the allocator of multimap m1
multimap <int, int>::allocator_type m1_Alloc;
m1_Alloc = m1.get_allocator( );
multimap <int, int> m3( less<int>( ), m1_Alloc );
m3.insert( Int_Pair( 3, 30 ) );
// Create a copy, multimap m4, of multimap m1
multimap <int, int> m4( m1 );
// Create a multimap m5 by copying the range m1[_First, _Last)
multimap <int, int>::const_iterator m1_bcIter, m1_ecIter;
m1_bcIter = m1.begin( );
m1_ecIter = m1.begin( );
m1_ecIter++;
m1_ecIter++;
//multimap <int, int> m5( m1_bcIter, m1_ecIter );
multimap <int, int> m5;
m5.insert( Int_Pair( 1, 10 ) );
m5.insert( Int_Pair( 2, 20 ) );
// Create a multimap m6 by copying the range m4[_First, _Last)
// and with the allocator of multimap m2
multimap <int, int>::allocator_type m2_Alloc;
m2_Alloc = m2.get_allocator( );
// multimap <int, int> m6(m4.begin( ), ++m4.begin( ), less<int>( ), m2_Alloc);
multimap <int, int> m6;
m6.insert( Int_Pair( 2, 20 ) );
m6.insert( Int_Pair( 1, 10 ) );
cout << "m1 =";
for ( m1_Iter = m1.begin( ); m1_Iter != m1.end( ); m1_Iter++ )
cout << " " << m1_Iter -> second;
cout << endl;
cout << "m2 =";
for ( m2_Iter = m2.begin( ); m2_Iter != m2.end( ); m2_Iter++ )
cout << " " << m2_Iter -> second;
cout << endl;
cout << "m3 =";
for ( m3_Iter = m3.begin( ); m3_Iter != m3.end( ); m3_Iter++ )
cout << " " << m3_Iter -> second;
cout << endl;
cout << "m4 =";
for ( m4_Iter = m4.begin( ); m4_Iter != m4.end( ); m4_Iter++ )
cout << " " << m4_Iter -> second;
cout << endl;
cout << "m5 =";
for ( m5_Iter = m5.begin( ); m5_Iter != m5.end( ); m5_Iter++ )
cout << " " << m5_Iter -> second;
cout << endl;
cout << "m6 =";
for ( m6_Iter = m6.begin( ); m6_Iter != m6.end( ); m6_Iter++ )
cout << " " << m6_Iter -> second;
cout << endl;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -