Reference
C Library
IOstream Library
Strings library
STL Containers
STL Algorithms
Miscellaneous
STL Containers
bitset
deque
list
map
multimap
multiset
priority_queue
queue
set
stack
vector
set
comparison operators
set::set
set::~set
member functions:
set::begin
set::clear
set::count
set::empty
set::end
set::equal_range
set::erase
set::find
set::get_allocator
set::insert
set::key_comp
set::lower_bound
set::max_size
set::operator=
set::rbegin
set::rend
set::size
set::swap
set::upper_bound
set::value_comp


set::clear

public member function
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