hash_map::size
Note
This API is obsolete. The alternative is unordered_map Class.
Returns the number of elements in the hash_map.
size_type size( ) const;
Return Value
The current length of the hash_map.
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_size.cpp
// compile with: /EHsc
#include <hash_map>
#include <iostream>
int main( )
{
using namespace std;
using namespace stdext;
hash_map<int, int> hm1, hm2;
hash_map<int, int>::size_type i;
typedef pair<int, int> Int_Pair;
hm1.insert(Int_Pair(1, 1));
i = hm1.size();
cout << "The hash_map length is " << i << "." << endl;
hm1.insert(Int_Pair(2, 4));
i = hm1.size();
cout << "The hash_map length is now " << i << "." << endl;
}
The hash_map length is 1. The hash_map length is now 2.
Requirements
Header: <hash_map>
Namespace: stdext