map::clear
Erases all the elements of a map.
void clear( );
Example
When compiling this example with the /Wp64 flag or on a 64-bit platform, compiler warning C4267 will be generated. For more information on this warning, see Compiler Warning (level 3) C4267.
// map_clear.cpp
// compile with: /EHsc
#include <map>
#include <iostream>
int main()
{
using namespace std;
map<int, int> m1;
map<int, int>::size_type i;
typedef pair<int, int> Int_Pair;
m1.insert(Int_Pair(1, 1));
m1.insert(Int_Pair(2, 4));
i = m1.size();
cout << "The size of the map is initially "
<< i << "." << endl;
m1.clear();
i = m1.size();
cout << "The size of the map after clearing is "
<< i << "." << endl;
}
The size of the map is initially 2. The size of the map after clearing is 0.
Requirements
Header: <map>
Namespace: std