set::size

Returns the number of elements in the set.

size_type size( ) const;

Return Value

The current length of the set.

Example

// 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;
}
The set length is 1.
The set length is now 2.

Requirements

Header: <set>

Namespace: std

See Also

Reference

set Class

set::size (STL Samples)

Standard Template Library