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 Class

set::size (STL Samples)

標準樣板程式庫