共用方式為


set::size

傳回集合中項目的數目。

size_type size( ) const;

傳回值

集合中目前的長度。

範例

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

int main( )
{
   using namespace std;
   set <int> s1;
   set <int> :: size_type i;
   
   s1.insert( 1 );
   i = s1.size( );
   cout << "The set length is " << i << "." << endl;

   s1.insert( 2 );
   i = s1.size( );
   cout << "The set length is now " << i << "." << endl;
}
  

需求

標頭: <set>

命名空間: std

請參閱

參考

set 類別

set::size (STL 範例)

標準樣板程式庫