clear

Syntax:

    #include <set>
    void clear();

The function clear() deletes all of the elements in the set. clear() runs in linear time.

For example, the following code uses clear() to reinitialize a set:

     // Create a set of characters
     set<char> charSet;
     charSet.insert( 'A' );
     charSet.insert( 'B' );
     charSet.insert( 'C' );
     charSet.clear();
     charSet.insert( 'A' );
     charSet.insert( 'D' );
     charSet.insert( 'E' );
     // Display the set
     set<char>::iterator theIterator;
     for( theIterator = charSet.begin(); theIterator != charSet.end(); theIterator++ ) {
       cout << *theIterator;
     }
     // output is "ADE"

Related Topics: erase