hash_map::clear

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
#define _DEFINE_DEPRECATED_HASH_CLASSES 0
#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

See Also

Concepts

hash_map Class

hash_map Members

Standard Template Library