clear [C++ Reference]
Keywords: stl,set,clear
Date: 2008-10-14T15:42:07-0700

[[clear]]
C++ Reference
Translations of this page?:

- en
- br-pt
- cn
- fr
- it
- jp
- pl
- ru
- tr

## 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

Edit this page • Old revisions
• • • Login • Index • Recent changes • RSS • cc •