VOOZH about

URL: https://www.geeksforgeeks.org/cpp/check-key-present-cpp-map-unordered_map/

⇱ Check if a key is present in a C++ map or unordered_map - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Check if a key is present in a C++ map or unordered_map

Last Updated : 30 Apr, 2024

A C++ map and unordered_map are initialized to some keys and their respective mapped values. 
Examples: 

Input : 
Map : 1 -> 4, 2 -> 6, 4 -> 6
Check1 : 5, Check2 : 4
Output : 5 : Not present, 4 : Present


C++ implementation : 

Output: 

5: Not Present
4: Present

Approach 2nd: 

we can also use the count function of the map in c++.

Implementation:

1. Map

Output:

5: Not Present

4: Present

2. Unordered Map

Output:

5: Not Present

4: Present


Comment