查找具有指定的键值的元素。
Type& at(
const Key& _Key
);
const Type& at(
const Key& _Key
) const;
参数
Parameter |
说明 |
_Key |
查找的键值。 |
返回值
组件的数据值的引用找到。
备注
如果找不到参数的键值,则该函数引发选件类 out_of_range Class对象。
示例
// map_at.cpp
// compile with: /EHsc
#include <map>
#include <iostream>
typedef std::map<char, int> Mymap;
int main()
{
Mymap c1;
c1.insert(Mymap::value_type('a', 1));
c1.insert(Mymap::value_type('b', 2));
c1.insert(Mymap::value_type('c', 3));
// find and show elements
std::cout << "c1.at('a') == " << c1.at('a') << std::endl;
std::cout << "c1.at('b') == " << c1.at('b') << std::endl;
std::cout << "c1.at('c') == " << c1.at('c') << std::endl;
return (0);
}
Output
c1.at('a') == 1
c1.at('b') == 2
c1.at('c') == 3
要求
标头: <map>
命名空间: std