size_type count ( const key_type& k ) const;
// 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; } |
unordered_map::find | 获取元素迭代器(公众成员函数) |
unordered_map::operator[] | 访问容器(公众成员函数) |
unordered_map::at | 访问容器(公众成员函数) |
unordered_map::size | 返回容器大小(公众成员函数) |