hash_map::count (STL/CLR)

 

For the latest documentation on Visual Studio 2017, see Visual Studio 2017 Documentation.

Finds the number of elements matching a specified key.

size_type count(key_type key);  

Parameters

key
Key value to search for.

The member function returns the number of elements in the controlled sequence that have equivalent ordering with key. You use it to determine the number of elements currently in the controlled sequence that match a specified key.

// cliext_hash_map_count.cpp   
// compile with: /clr   
#include <cliext/hash_map>   
  
typedef cliext::hash_map<wchar_t, int> Myhash_map;   
int main()   
    {   
    Myhash_map c1;   
    c1.insert(Myhash_map::make_value(L'a', 1));   
    c1.insert(Myhash_map::make_value(L'b', 2));   
    c1.insert(Myhash_map::make_value(L'c', 3));   
  
// display contents " [a 1] [b 2] [c 3]"   
    for each (Myhash_map::value_type elem in c1)   
        System::Console::Write(" [{0} {1}]", elem->first, elem->second);   
    System::Console::WriteLine();   
  
    System::Console::WriteLine("count(L'A') = {0}", c1.count(L'A'));   
    System::Console::WriteLine("count(L'b') = {0}", c1.count(L'b'));   
    System::Console::WriteLine("count(L'C') = {0}", c1.count(L'C'));   
    return (0);   
    }  
  

 [a 1] [b 2] [c 3]  
count(L'A') = 0  
count(L'b') = 1  
count(L'C') = 0  

Header: <cliext/hash_map>

Namespace: cliext

hash_map (STL/CLR)
hash_map::equal_range (STL/CLR)

Show: