hash_map::clear
Note
This API is obsolete. The alternative is unordered_map Class.
Erases all the elements of a hash_map.
void clear( );
Remarks
In Visual C++ .NET 2003, members of the <hash_map> and <hash_set> header files are no longer in the std namespace, but rather have been moved into the stdext namespace. See The stdext Namespace for more information.
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.
// hash_map_clear.cpp
// compile with: /EHsc
#include <hash_map>
#include <iostream>
int main( )
{
using namespace std;
using namespace stdext;
hash_map<int, int> hm1;
hash_map<int, int>::size_type i;
typedef pair<int, int> Int_Pair;
hm1.insert(Int_Pair(1, 1));
hm1.insert(Int_Pair(2, 4));
i = hm1.size();
cout << "The size of the hash_map is initially "
<< i << "." << endl;
hm1.clear();
i = hm1.size();
cout << "The size of the hash_map after clearing is "
<< i << "." << endl;
}
The size of the hash_map is initially 2. The size of the hash_map after clearing is 0.
Requirements
Header: <hash_map>
Namespace: stdext