// unordered_set::find #include #include #include template void print_set(std::unordered_set& myset) { std::cout << "myset contains:"; for (auto it=myset.begin(); it!=myset.end(); ++it) std::cout << ' ' << *it; std::cout << '\n'; } int main () { std::unordered_set myset; std::unordered_set::iterator it; std::string word[] = { "sugar", "choco", "milk", "banana", "coffee" }; // unordered_set some initial values: for (int i=0; i<5; i++) myset.emplace(word[i]); print_set(myset); it=myset.find(std::string("biscuits")); if(it != myset.end()) { myset.erase (it); std::cout << "'biscuits' erased\n"; } else std::cout << "'biscuits' not found\n"; print_set(myset); myset.erase (myset.find(std::string("milk"))); std::cout << "'milk' erased\n"; print_set(myset); return 0; }