![]() |
---|
此 API 已过时。另一种方法是 unordered_map Class。 |
查找在一 hash_map 的元素具有指定的键值。
Type& at(
const Key& _Key
);
const Type& at(
const Key& _Key
) const;
参数
Parameter |
描述 |
_Key |
将找到元素的键值。 |
返回值
与找到的元素数据值的引用。
备注
如果找不到参数的键值,则该函数引发选件类 out_of_range Class对象。
在 Visual C++ .NET 2003 中,<hash_map> 和 <hash_set> 标头文件的成员中不再标准,命名空间,而是将 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