Quantcast
Channel: How to find if a given key exists in a std::map - Stack Overflow
Viewing all articles
Browse latest Browse all 16

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

$
0
0

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 all articles
Browse latest Browse all 16

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>