check if key exists in map c 2b 2b

Solutions on MaxInterview for check if key exists in map c 2b 2b by the best coders in the world

showing results for - "check if key exists in map c 2b 2b"
Wilbert
21 May 2019
1if ( m.find("f") == m.end() ) {
2  // not found
3} else {
4  // found
5}
Giulio
03 Mar 2019
1#include<map>
2
3int main(){
4
5  	map<int,char> m;
6  	
7  	char ch = '!';
8  
9	if (m.find(ch) != m.end()) {
10		std::cout << "Key found";
11	} else {
12		std::cout << "Key not found";
13	}
14  
15	return 0;
16}
Filippo
03 Nov 2017
1if ( m.find("f") == m.end() ) {
2  // not found
3} else {
4  // found
5}
6
Marylou
09 Jan 2021
1if ( !(myMap.find("key") == myMap.end()) ) {	// "key" exists	
2  
3} else {	// not found	
4  
5}
6
Maite
23 Jan 2020
1#include <iostream>
2#include <unordered_map>
3#include <algorithm>
4 
5int main()
6{
7    std::unordered_map<char,int> m;
8 
9    std::string s("abcba");
10    std::for_each(s.begin(), s.end(), [&m](char &c) { m[c]++; });
11 
12    char ch = 's';
13 
14    if (m.find(ch) != m.end()) {
15        std::cout << "Key found";
16    } else {
17        std::cout << "Key not found";
18    }
19 
20    return 0;
21}
22
similar questions
queries leading to this page
check if key exists in map c 2b 2b