map::upper_bound
키와 값을 지정 된 키 보다 큰를 가진 반복기 맵의 첫 번째 요소를 반환 합니다.
iterator upper_bound(
const Key& _Key
);
const_iterator upper_bound(
const Key& _Key
) const;
매개 변수
- _Key
검색 되는 지도 요소의 정렬 키 값을 비교할 인수 키 값입니다.
반환 값
반복기 또는 const_iterator 요소의 인수 키 보다 큰 또는 주소가 일치 하면 맵의 마지막 요소 뒤에 위치 하는 키와 키를 찾을 수 있는 맵의 위치를 해결 합니다.
반환 값을 할당 하는 경우는 const_iterator, 지도 개체를 수정할 수 없습니다.반환 값을 할당 하는 경우는 반복기, 지도 개체를 수정할 수 있습니다.
예제
// map_upper_bound.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.upper_bound( 2 );
cout << "The first element of map m1 with a key "
<< "greater than 2 is: "
<< m1_RcIter -> second << "." << endl;
// If no match is found for the key, end is returned
m1_RcIter = m1. upper_bound ( 4 );
if ( m1_RcIter == m1.end( ) )
cout << "The map m1 doesn't have an element "
<< "with a key greater than 4." << endl;
else
cout << "The element of map m1 with a key > 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.begin( );
m1_RcIter = m1. upper_bound ( m1_AcIter -> first );
cout << "The 1st element of m1 with a key greater than\n"
<< "that of the initial element of m1 is: "
<< m1_RcIter -> second << "." << endl;
}
요구 사항
헤더: <map>
네임 스페이스: std