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

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




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 << "'a') == " <<'a') << std::endl; 
    std::cout << "'b') == " <<'b') << std::endl; 
    std::cout << "'c') == " <<'c') << std::endl; 

    return (0); 
    }'a') == 10'b') == 20'c') == 30

Header: <unordered_map>

Namespace: std

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