共用方式為


multimap::count

傳回項目數索引鍵符合參數指定索引鍵的多重對應的。

size_type count( 
   const Key& _Key 
) const;

參數

  • _Key
    從多重對應會符合之項目的索引鍵。

傳回值

排序鍵與參數相符索引鍵之項目的數目;0,如果多重對應不包含具有相符索引鍵的項目。

備註

成員函式傳回項目數範圍的

[lower_bound (_Key), upper_bound (_Key))

有一個索引鍵值 _Key。

範例

當編譯這個範例會使用 /Wp64 旗標或在 64 位元平台時,編譯器警告 C4267 會產生。 如需這項警告的詳細資訊,請參閱 編譯器警告 (層級 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;
}
  

需求

標頭:<map>

命名空間: std

請參閱

參考

multimap 類別

標準樣板程式庫