次の方法で共有


hash_map::begin

[!メモ]

この API は、互換性のために残されています。代わりに unordered_map クラスです。

hash_mapの最初の要素を指定する反復子を返します。

const_iterator begin( ) const; 
iterator begin( );

戻り値

空のhash_mapを成功させるhash_mapの最初の要素または位置をアドレス双方向反復子。

解説

begin の戻り値が const_iteratorに割り当てられている場合、hash_mapのオブジェクト要素を変更できません。begin の戻り値が **[iterator]**に割り当てられている場合、hash_mapのオブジェクト要素を変更できます。

Visual C++ .NET 2003では、<hash_map><hash_set> ヘッダー ファイルのメンバーはstdの名前空間に存在しなくなりましたが、ではなくstdextの名前空間に型。詳細については、「The stdext Namespace」を参照してください。

使用例

// 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 Class

標準テンプレート ライブラリ