다음을 통해 공유


set::count

키 매개 변수에 지정 된 키가 일치 하는 집합에서 요소의 개수를 반환 합니다.

size_type count(
   const Key& _Key
) const;

매개 변수

  • _Key
    키 집합에서 일치 하는 요소입니다.

반환 값

매개 변수 키 정렬 키가 일치 하는 요소 집합을 포함 하는 경우 1입니다.집합 키와 일치 하는 요소를 포함 하지 않는 경우 0입니다.

설명

멤버 함수 다음 범위 내에서 요소의 개수를 반환합니다.

[lower_bound (_Key ), upper_bound (_Key ) ).

예제

이 예제를 컴파일하는 경우는 /Wp64 플래그를 지정 하거나 컴파일러 C4267 경고는 64 비트 플랫폼에서 생성 됩니다.이 경고에 대 한 자세한 내용은 컴파일러 경고 (수준 3) C4267.

// set_count.cpp
// compile with: /EHsc
#include <set>
#include <iostream>

int main()
{
    using namespace std;
    set<int> s1;
    set<int>::size_type i;

    s1.insert(1);
    s1.insert(1);

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

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

요구 사항

헤더: <set>

네임 스페이스: std

참고 항목

참조

set Class

set::count (STL Samples)

표준 템플릿 라이브러리