Prerequisite : Unordered maps in STL
Unordered_map : unordered_map is an associated container that stores elements formed by the combination of key value and a mapped value. The key value is used to uniquely identify the element and mapped value is the content associated with the key. Both key and value can be of any type predefined or user-defined.
unordered_map :: at(): This function in C++ unordered_map returns the reference to the value with the element as key k.
unordered_map.at(k); Parameter: It is the key value of the element whose mapped value we want to access. Return type : A reference to the mapped value of the element with a key value equivalent
Note : The method gives run-time error if key is not present.
Value of key mp['second'] = 2 Exception at _Map_base::at
Practical Application : std :: unordered_map :: at() function can be used to access the mapped value and thus can edit, update etc.
Computer Application: 100 Chemistry: 98 Physics: 97 Maths: 100
How unordered_map at() is different from unordered_map operator()
- Both at() and operator is used to refer the element present at the given position, the only difference is, at() throws out-of-range exception whereas operator shows undefined behavior i.e. if operator is used to find the value corresponding to key and if key is not present in unordered map, it will first insert the key into the map and then assign the default value ‘0’ corresponding to that key. .
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Different types of range-based for loop iterators in C++
- Learn C++ Programming Step by Step - A 20 Day Curriculum!
- Check whether count of odd and even factors of a number are equal
- History of Computer Games
- Check if Array elements can be maximized upto M by adding all elements from another array
- Why do we need reference variables if we have pointers
- Similarities and Difference between Java and C++
- Macros and its types in C/C++
- How to find index of a given element in a Vector in C++
- Difference between MS SQL Server and IBM DB2
- Introduction of MariaDB
- Print all lexicographical greater permutations of a given string
- Print all K digit repeating numbers in a very large number
- Introduction to Complex Objects and Composition
- NULL undeclared error in C/C++ and how to resolve it
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : ranjeetgautam13032