1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
// unordered_map::count
#include <iostream>
#include <string>
#include <unordered_map>
int main ()
{
std::unordered_map<std::string,double> mymap = {
{"Burger",2.99},
{"Fries",1.99},
{"Soda",1.50} };
for (auto& x: {"Burger","Pizza","Salad","Soda"}) {
if (mymap.count(x)>0)
std::cout << "mymap has " << x << std::endl;
else
std::cout << "mymap has no " << x << std::endl;
}
return 0;
}
|