共用方式為


multiset::difference_type

可以用來表示多重集 (Multiset) 項目數的某個範圍的項目之間的帶正負號的整數 (Unsigned Integer) 型別指向的 Iterator。

typedef typename allocator_type::difference_type difference_type;

備註

,當減去或加入應用程式的 Iterator 時, difference_type 為傳回的型別。 difference_type 通常用來表示項目數目範圍 [_First, _Last)。 _First Iterator 之間,並 _Last,包括項目指向 _First 和項目的範圍,,但不包含項目,指向 _Last。

請注意,雖然為符合輸入 Iterator 需求,包括雙向 Iterator 可用於類別與集合的可反轉的容器所支援的所有 Iterator,在 Iterator 之間的減法適用於向量的隨機存取的容器所提供的隨機存取 Iterator 只支援 difference_type

範例

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

int main( )
{
   using namespace std;

   multiset <int> ms1;
   multiset <int>::iterator ms1_Iter, ms1_bIter, ms1_eIter;

   ms1.insert( 20 );
   ms1.insert( 10 );
   ms1.insert( 20 );

   ms1_bIter = ms1.begin( );
   ms1_eIter = ms1.end( );

   multiset <int>::difference_type   df_typ5, df_typ10, df_typ20;

   df_typ5 = count( ms1_bIter, ms1_eIter, 5 );
   df_typ10 = count( ms1_bIter, ms1_eIter, 10 );
   df_typ20 = count( ms1_bIter, ms1_eIter, 20 );

   // The keys, and hence the elements, of a multiset are not unique
   cout << "The number '5' occurs " << df_typ5
        << " times in multiset ms1.\n";
   cout << "The number '10' occurs " << df_typ10
        << " times in multiset ms1.\n";
   cout << "The number '20' occurs " << df_typ20
        << " times in multiset ms1.\n";

   // Count the number of elements in a multiset 
   multiset <int>::difference_type  df_count = 0;
   ms1_Iter = ms1.begin( );
   while ( ms1_Iter != ms1_eIter)
   {
      df_count++;
      ms1_Iter++;
   }

   cout << "The number of elements in the multiset ms1 is: " 
        << df_count << "." << endl;
}
  
  
  
  

需求

標題: <set>

命名空間: std

請參閱

參考

multiset Class

標準樣板程式庫