共用方式為


hash_map::at

注意事項注意事項

這個 API 已經過時。這個選項是 unordered_map Class

尋找一 hash_map 的項目具有指定索引鍵值。

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

參數

參數

描述

_Key

要尋找之項目的索引鍵值。

傳回值

對找到的項目之資料值的參考。

備註

如果找不到引數索引鍵值,則函式會擲回類別 out_of_range Class物件。

在 Visual C++ .NET Pocket PC, <hash_map><hash_set> 標頭檔 (Header File) 的成員不在 std 命名空間,,而是移至 stdext 命名空間。 如需詳細資訊,請參閱 stdext 命名空間

範例

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

Output

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

需求

標題: <hash_map>

命名空間: stdext

請參閱

參考

hash_map Class

標準樣板程式庫