multimap::swap
交換兩個 multimaps 的項目。
void swap(
multimap<Key, Type, Traits, Allocator>& _Right
);
參數
- _Right
項目將切換與 multimap _Left的 multimap 提供項目會交換、multimap。
備註
成員函式不失效。multimaps 兩個指定的項目已交換參考、指標或 Iterator。
範例
// multimap_swap.cpp
// compile with: /EHsc
#include <map>
#include <iostream>
int main( )
{
using namespace std;
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;
}
需求
標題: <map>
命名空間: std