次の方法で共有


multiset::count

キーがパラメーター指定したキーに一致する複数セット内の要素数を返します。

size_type count(
   const Key& _Key
) const;

パラメーター

  • _Key
    多重セットに一致する要素のキー。

戻り値

並べ替えキーがパラメーターのキーに一致する複数セット内の要素数。

解説

このメンバー関数は、要素の数の x 範囲を返します

[lower_bound (_Key ), upper_bound (_Key ) )。

使用例

/Wp64 フラグを持つまたは 64 ビット プラットフォームでこの例をコンパイルすると、コンパイラの警告 C4267 エラーが生成されます。この警告の詳細については、コンパイラの警告 (レベル 3) C4267を参照してください。

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

int main()
{
    using namespace std;
    multiset<int> ms1;
    multiset<int>::size_type i;

    ms1.insert(1);
    ms1.insert(1);
    ms1.insert(2);

    // Elements do not need to be unique in multiset,
    // so duplicates are allowed and counted.
    i = ms1.count(1);
    cout << "The number of elements in ms1 with a sort key of 1 is: "
         << i << "." << endl;

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

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

必要条件

ヘッダー: <set>

名前空間: std

参照

関連項目

multiset Class

標準テンプレート ライブラリ