map::find

요소에 지정 된 키에 해당 하는 키가 지도 위치 주소를 지정 하는 반복기를 반환 합니다.

iterator find(
   const Key& _Key
);
const_iterator find(
   const Key& _Key
) const;

매개 변수

  • _Key
    검색 되는 지도 요소의 정렬 키와 일치 하는 키 값입니다.

반환 값

요소의 위치를 해결 하는 지정 된 키 또는 키에 일치 하는 항목이 있는 경우 맵의 마지막 요소 뒤에 위치 하는 반복기입니다.

설명

멤버 함수 이내 비교가 관계 기반 첫 순서는 이진 조건부 인수 키를 정렬 키 같습니다 맵에서 요소를 해결 하는 반복기를 반환 합니다.

경우 반환 값의 찾기 할당 되는 const_iterator, 맵 개체를 수정할 수 없습니다.경우 반환 값의 찾기 할당 되는 반복기, 맵 개체를 수정할 수 있습니다

예제

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

int main( )
{
   using namespace std;
   map <int, int> m1;
   map <int, int> :: const_iterator m1_AcIter, m1_RcIter;
   typedef pair <int, int> Int_Pair;

   m1.insert ( Int_Pair ( 1, 10 ) );
   m1.insert ( Int_Pair ( 2, 20 ) );
   m1.insert ( Int_Pair ( 3, 30 ) );

   m1_RcIter = m1.find( 2 );
   cout << "The element of map m1 with a key of 2 is: "
        << m1_RcIter -> second << "." << endl;

   // If no match is found for the key, end( ) is returned
   m1_RcIter = m1.find( 4 );

   if ( m1_RcIter == m1.end( ) )
      cout << "The map m1 doesn't have an element "
           << "with a key of 4." << endl;
   else
      cout << "The element of map m1 with a key of 4 is: "
           << m1_RcIter -> second << "." << endl;

   // The element at a specific location in the map can be found 
   // using a dereferenced iterator addressing the location
   m1_AcIter = m1.end( );
   m1_AcIter--;
   m1_RcIter = m1.find( m1_AcIter -> first );
   cout << "The element of m1 with a key matching "
        << "that of the last element is: "
        << m1_RcIter -> second << "." << endl;
}
  
  
  

요구 사항

헤더: <map>

네임 스페이스: std

참고 항목

참조

map Class

map::insert, map::find, 및 map::end

표준 템플릿 라이브러리