Quantcast
Viewing latest article 4
Browse Latest Browse All 16

Answer by Denis Sablukov for How to find if a given key exists in a std::map

C++20 gives us std::map::contains to do that.

#include <iostream>#include <string>#include <map>int main(){    std::map<int, std::string> example = {{1, "One"}, {2, "Two"},                                      {3, "Three"}, {42, "Don\'t Panic!!!"}};    if(example.contains(42)) {        std::cout << "Found\n";    } else {        std::cout << "Not found\n";    }}

Viewing latest article 4
Browse Latest Browse All 16

Trending Articles