set::clear

Erases all the elements of a set.

void clear( );

Example

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

int main( )
{
   using namespace std;   
   set <int> s1;
   
   s1.insert( 1 );
   s1.insert( 2 );

   cout << "The size of the set is initially " << s1.size( )
        << "." << endl;

   s1.clear( );
   cout << "The size of the set after clearing is " 
        << s1.size( ) << "." << endl;
}
The size of the set is initially 2.
The size of the set after clearing is 0.

Requirements

Header: <set>

Namespace: std

See Also

Reference

set Class

set::empty and set::clear

Standard Template Library