hash_map::begin

备注

此 API 已过时。替代为 unordered_map 类

返回解决在 hash_map 迭代器的第一个元素。

const_iterator begin( ) const; 
iterator begin( );

返回值

在解决 hash_map 的第一个元素或一位置的双向迭代器成功空 hash_map。

备注

如果 begin 的返回值分配为 const_iterator,不能修改。hash_map 对象的元素。 如果 begin 的返回值赋给 迭代器,可以修改在 hash_map 对象的元素。

在Visual C++ .NET 2003中,成员<hash_map><hash_set> 头文件不再在std命名空间,而是已经进入了stdext命名空间。 有关更多信息,请参见 stdext 命名空间

示例

// 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;
}
  

要求

标头: <hash_map>

**命名空间:**stdext

请参见

参考

hash_map 类

标准模板库