map::count
키 매개 변수를 지정 된 키가 일치 하는 맵에 요소의 개수를 반환 합니다.
size_type count(
const Key& _Key
) const;
매개 변수
- _Key
키 값에서 일치 하는 요소입니다.
반환 값
1; 지도 정렬 키 매개 변수 키가 일치 하는 요소가 포함 되어 있는 경우 지도 요소는 일치 하는 키가 포함 되지 않은 경우 0입니다.
설명
요소 개수를 반환 하는 멤버 함수 x 범위
[lower_bound (_Key ), upper_bound (_Key ) )
맵의 고유 연관 컨테이너인 경우 1 또는 0입니다.
예제
이 예제를 컴파일하는 경우는 /Wp64 플래그를 지정 하거나 컴파일러 C4267 경고는 64 비트 플랫폼에서 생성 됩니다.이 경고에 대 한 자세한 내용은 컴파일러 경고 (수준 3) C4267.
// map_count.cpp
// compile with: /EHsc
#include <map>
#include <iostream>
int main()
{
using namespace std;
map<int, int> m1;
map<int, int>::size_type i;
typedef pair<int, int> Int_Pair;
m1.insert(Int_Pair(1, 1));
m1.insert(Int_Pair(2, 1));
m1.insert(Int_Pair(1, 4));
m1.insert(Int_Pair(2, 1));
// Keys must be unique in map, so duplicates are ignored
i = m1.count(1);
cout << "The number of elements in m1 with a sort key of 1 is: "
<< i << "." << endl;
i = m1.count(2);
cout << "The number of elements in m1 with a sort key of 2 is: "
<< i << "." << endl;
i = m1.count(3);
cout << "The number of elements in m1 with a sort key of 3 is: "
<< i << "." << endl;
}
요구 사항
헤더: <map>
네임 스페이스: std