次の方法で共有


hash_map::at

[!メモ]

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

指定されたキー値を持つhash_mapの要素を検索します。

Type& at(
   const Key& _Key
);
const Type& at(
   const Key& _Key
) const;

パラメーター

パラメーター

説明

_Key

検索する要素のキー値。

戻り値

見つかった要素のデータ値への参照。

解説

引数のキー値が見つからない場合、この関数は、out_of_range Class クラスのオブジェクトをスローします。

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

使用例

// hash_map_at.cpp
// compile with: /EHsc
#include <hash_map>
#include <iostream>

int main( )
{
   using namespace std;
   using namespace stdext;
   typedef pair <const int, int> cInt2Int;
   hash_map <int, int> hm1;
   
   // Insert data values
   hm1.insert ( cInt2Int ( 1, 10 ) );
   hm1.insert ( cInt2Int ( 2, 20 ) );
   hm1.insert ( cInt2Int ( 3, 30 ) );

   cout  << "The values of the mapped elements are:";
   for ( int i = 1 ; i <= hm1.size() ; i++ )
      cout << " " << hm1.at(i);
   cout << "." << endl;
}

出力

The values of the mapped elements are: 10 20 30.

必要条件

ヘッダー: <hash_map>

名前空間: のstdext

参照

関連項目

hash_map Class

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