size_type count ( const key_type& k ) const;
// unordered_set::count #include <iostream> #include <string> #include <unordered_set> int main () { std::unordered_set<std::string> myset = { "hat", "umbrella", "suit" }; for (auto& x: {"hat","sunglasses","suit","t-shirt"}) { if (myset.count(x)>0) std::cout << "myset has " << x << std::endl; else std::cout << "myset has no " << x << std::endl; } return 0; } |
unordered_set::find | 获取元素迭代器(公众成员函数) |
unordered_set::size | 返回容器大小(公众成员函数) |