Share via


hash_map::begin

[!NOTA]

Esta API está obsoleta.La alternativa es unordered_map Class.

Devuelve un iterador que dirige el primer elemento del hash_map.

const_iterator begin( ) const; 
iterator begin( );

Valor devuelto

Un iterador bidireccional que dirige el primer elemento del hash_map o la ubicación que funciona correctamente un hash_map vacío.

Nota

Si el valor devuelto begin se asigna a const_iterator, los elementos en el objeto de hash_map no pueden modificarse.Si el valor devuelto begin se asigna a iterator, los elementos en el objeto de hash_map pueden modificarse.

En Visual C++ .NET 2003, los miembros de los archivos de encabezado <hash_map> y <hash_set> ya no están en el espacio de nombres std, pero se han movido bastante al espacio de nombres stdext.Vea El espacio de nombres stdext para obtener más información.

Ejemplo

// hash_map_begin.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> :: iterator hm1_Iter;
   hash_map <int, int> :: const_iterator hm1_cIter;
   typedef pair <int, int> Int_Pair;

   hm1.insert ( Int_Pair ( 0, 0 ) );
   hm1.insert ( Int_Pair ( 1, 1 ) );
   hm1.insert ( Int_Pair ( 2, 4 ) );

   hm1_cIter = hm1.begin ( );
   cout << "The first element of hm1 is " 
        << hm1_cIter -> first << "." << endl;
   
   hm1_Iter = hm1.begin ( );
   hm1.erase ( hm1_Iter );

   // The following 2 lines would err because the iterator is const
   // hm1_cIter = hm1.begin ( );
   // hm1.erase ( hm1_cIter );

   hm1_cIter = hm1.begin( );
   cout << "The first element of hm1 is now " 
        << hm1_cIter -> first << "." << endl;
}
  
  

Requisitos

Encabezado: <hash_map>

Stdext deEspacio de nombres:

Vea también

Referencia

hash_map Class

Biblioteca de plantillas estándar