Udostępnij za pośrednictwem


hash_map::operator (STL/CLR)

Mapuje klucza skojarzonej wartości mapowane.

    mapped_type operator[](key_type key);

Parametry

  • klucz
    Wartość klucza wyszukiwania.

Uwagi

Członek funkcje przedsięwzięciach, aby znaleźć element z równoważnym nakazujące key.Jeśli zostanie znaleziony, zwracana jest wartość skojarzona mapowane; w przeciwnym razie wstawia value_type(key, mapped_type()) i zwraca skojarzony (domyślnie) mapowane wartości.Należy użyć go odszukać zmapowane wartości, biorąc pod uwagę skojarzonego z nim klucza, lub do zapewnienia, że istnieje wpis dla klucza, jeśli stwierdzono brak.

Przykład

// cliext_hash_map_operator_sub.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("c1[{0}] = {1}", 
        L'A', c1[L'A']); 
    System::Console::WriteLine("c1[{0}] = {1}", 
        L'b', c1[L'b']); 
 
// redisplay altered contents 
    for each (Myhash_map::value_type elem in c1) 
        System::Console::Write(" [{0} {1}]", elem->first, elem->second); 
    System::Console::WriteLine(); 
 
// alter mapped values and redisplay 
    c1[L'A'] = 10; 
    c1[L'c'] = 13; 
    for each (Myhash_map::value_type elem in c1) 
        System::Console::Write(" [{0} {1}]", elem->first, elem->second); 
    System::Console::WriteLine(); 
    return (0); 
    } 
 
  

Wymagania

Nagłówek: < cliext/hash_map >

Obszar nazw: cliext

Zobacz też

Informacje

hash_map (STL/CLR)

hash_map::find (STL/CLR)

hash_map::insert (STL/CLR)