if(m.contains(key))
//true if contains
if ( m.find("f") == m.end() ) {
// not found
} else {
// found
}
#include <iostream>
#include <unordered_map>
#include <algorithm>
int main()
{
std::unordered_map<char,int> m;
std::string s("abcba");
std::for_each(s.begin(), s.end(), [&m](char &c) { m[c]++; });
char ch = 's';
if (m.find(ch) != m.end()) {
std::cout << "Key found";
} else {
std::cout << "Key not found";
}
return 0;
}
Code Example |
---|
Cpp :: how to make a segment tree in c++ |
Cpp :: c++ set element at index |
Cpp :: constants in cpp |
Cpp :: c++ split string by sstream |
Cpp :: for statement in c++ |
Cpp :: longest increasing subsequence nlogn c++ |
Cpp :: how to initialize priority queue c++ |
Cpp :: |