Reference:
Erases all the elements of a map.
Function:
void clear( );
Example:
Output:
The size of the map is initially 2.
The size of the map after clearing is 0.
Erases all the elements of a map.
Function:
void clear( );
Example:
#include <map>
#include <iostream>
int main( )
{
using namespace std;
map <int, int> m1;
int 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;
}
Output:
The size of the map is initially 2.
The size of the map after clearing is 0.