다음을 통해 공유


multimap::insert

요소 또는 요소 범위에 있는 multimap 삽입합니다.

iterator insert(
   const value_type& _Val
);
iterator insert(
   iterator _Where,
   const value_type& _Val
);
template<class InputIterator> 
   void insert(
      InputIterator _First,
      InputIterator _Last
   );
template<class ValTy>
   iterator insert(
      ValTy&& _Val
);
template<class ValTy>
   iterator insert(
      const_iterator _Where,
      ValTy&& _Val
);

매개 변수

Parameter

설명

_Val

Multimap는 해당 요소 또는 더 일반적으로 키 정렬 변환과 요소가 이미 포함 되어 있지 않으면 multimap에 삽입할 요소의 값입니다.

_Where

올바른 삽입 지점에 대 한 검색을 시작할 위치에 대 한 힌트입니다.

_First

지도에서 복사할 첫 번째 요소의 위치입니다.

_Last

지도에서 복사 하는 마지막 요소는 위치입니다.

반환 값

삽입 멤버 함수 새 요소 multimap에 삽입 된 위치를 가리키는 반복기를 반환 합니다.

설명

Value_type 요소의 값 정렬 된 쌍의 키 값과 같은 첫 번째 구성 요소와 다른 구성 요소에 데이터 값과 같은 수 있도록 요소를 한 쌍입니다.

삽입 하면 발생할 수 있습니다 힌트 버전 삽입 로그 시간 대신에 amortized 상수 시간에 바로 삽입 지점 다음에 오는 _Where.

셋째 멤버 함수는 반복기 범위에 의해 주소가 지정 된 각 요소에 해당 지도 시퀀스의 요소 값 삽입 [_First, _Last) 지정 된 집합입니다.

마지막으로 두 명의 멤버 함수를 제외 하 고 처음 두와 똑같이 동작 _Val 삽입 된 값을 생성 하는 데 사용 됩니다.

예제

// multimap_insert.cpp
// compile with: /EHsc
#include <map>
#include <iostream>
#include <string>

int main( )
{
   using namespace std;
   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 << "," << endl;

   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 ) );

   // The templatized version inserting a range
   m2.insert( ++m1.begin( ), --m1.end( ) );

   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;

    // The templatized versions move constructing elements
    multimap<int, string> m3, m4;
    pair<int, string> is1(1, "a"), is2(2, "b");

    m3.insert(move(is1));
    cout << "After the move insertion, m3 contains:" << endl
      << " " << m3.begin()->first
      << " => " << m3.begin()->second
      << endl;

    m4.insert(c4.begin(),move(is2));
    cout << "After the move insertion, m4 contains:" << endl
      << " " << m4.begin()->first
      << " => " << m4.begin()->second
      << endl;
}
  
  
  
  
  

요구 사항

헤더: <map>

네임 스페이스: std

참고 항목

참조

multimap Class

표준 템플릿 라이브러리