다음을 통해 공유


hash_map::count

참고

이 API는 사용되지 않습니다.unordered_map 클래스를 대신 사용하는 것이 좋습니다.

Returns the number of elements in a hash_map whose key matches a parameter-specified key.

size_type count( 
   const Key& _Key 
) const;

매개 변수

  • _Key
    The key value of the elements to be matched from the hash_map.

반환 값

1 if the hash_map contains an element whose sort key matches the parameter key; 0 if the hash_map doesn't contain an element with a matching key.

설명

The member function returns the number of elements x in the range

[lower_bound (_Key ), upper_bound (_Key ) )

which is 0 or 1 in the case of hash_map, which is a unique associative container.

Visual C++.NET 2003에서, <hash_map><hash_set> 헤더 파일의 멤버는 더 이상 std 네임스페이스에 존재하지 않습니다. 대신 stdext 네임스페이스로 이동되었습니다. 자세한 내용은 stdext 네임스페이스를 참조하십시오.

예제

When compiling this example with the /Wp64 flag or on a 64-bit platform, compiler warning C4267 will be generated. For more information on this warning, see 컴파일러 경고 (수준 3) C4267.

// hash_map_count.cpp
// compile with: /EHsc
#include <hash_map>
#include <iostream>

int main()
{
    using namespace std;
    using namespace stdext;
    hash_map<int, int> hm1;
    hash_map<int, int>::size_type i;
    typedef pair<int, int> Int_Pair;

    hm1.insert(Int_Pair (1, 1));
    hm1.insert(Int_Pair (2, 1));
    hm1.insert(Int_Pair (1, 4));
    hm1.insert(Int_Pair (2, 1));

    // Keys must be unique in hash_map, so duplicates are ignored
    i = hm1.count(1);
    cout << "The number of elements in hm1 with a sort key of 1 is: "
         << i << "." << endl;

    i = hm1.count(2);
    cout << "The number of elements in hm1 with a sort key of 2 is: "
         << i << "." << endl;

    i = hm1.count(3);
    cout << "The number of elements in hm1 with a sort key of 3 is: "
         << i << "." << endl;
}
  

요구 사항

헤더: <hash_map>

네임스페이스: stdext

참고 항목

참조

hash_map 클래스

표준 템플릿 라이브러리