hash_map::at

备注

此 API 已过时。替代为 unordered_map 类

查找一个 hash_map 的元素与某个指定的键值。

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

参数

参数

说明

_Key

将找到元素的键值。

返回值

与找到的元素数据值的引用。

备注

如果关键参数未找到值,则该函数引发类对象。out_of_range 类

在Visual C++ .NET 2003中,成员<hash_map><hash_set> 头文件不再在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 类

标准模板库