다음을 통해 공유


multimap::count

Returns the number of elements in a multimap whose keys match a parameter-specified key.

size_type count( 
   const Key& _Key 
) const;

매개 변수

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

반환 값

The number of elements whose sort keys match the parameter key; 0 if the multimap doesn't contain an element with a matching key.

설명

The member function returns the number of elements in the range

[lower_bound (_Key ), upper_bound (_Key ) )

that have a key value _Key.

예제

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.

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

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

    // Elements do not need to have unique keys in multimap,
    // so duplicates are allowed and counted
    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;
}
  

요구 사항

헤더: <맵>

네임스페이스: std

참고 항목

참조

multimap 클래스

표준 템플릿 라이브러리