public member function

std::set::clear

<set>
void clear ( );
Clear content
All the elements in the set container are dropped: their destructors are called, and then they are removed from the container, leaving it with a size of 0.

Parameters

none

Return value

none

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// set::clear
#include <iostream>
#include <set>
using namespace std;

int main ()
{
  set<int> myset;
  set<int>::iterator it;

  myset.insert (100);
  myset.insert (200);
  myset.insert (300);

  cout << "myset contains:";
  for (it=myset.begin(); it!=myset.end(); ++it)
    cout << " " << *it;

  myset.clear();
  myset.insert (1101);
  myset.insert (2202);

  cout << "\nmyset contains:";
  for (it=myset.begin(); it!=myset.end(); ++it)
    cout << " " << *it;

  cout << endl;

  return 0;
}


Output:
myset contains: 100 200 300
myset contains: 1101 2202

Complexity

Linear in size (destructors).

See also