unordered_map::at

Finds an element in a unordered_map with a specified key value.

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

Parameter

Description

_Key

The key value to find.

A reference to the data value of the element found.

If the argument key value is not found, then the function throws an object of class out_of_range.

// unordered_map_at.cpp
// compile with: /EHsc
#include <unordered_map>
#include <iostream>

typedef std::unordered_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); 
    } 

c1.at('a') == 10
c1.at('b') == 20
c1.at('c') == 30

Header: <unordered_map>

Namespace: std

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft