The cplusplus.com page about unordered_set member function "erase" has this sample code that removes the set element "France" when an exact matching string is supplied.
[EDIT: I cite this code for its brevity and clarity. My actual project uses unordered_set for reasons not necessarily present in this example. However a solution that works on this sample code would work in my project.]
How would I modify this to remove all the elements that have matches to a smaller string?
For example, removing all the elements with an "F" as the first character. [EDIT: targeting the first character is merely an example. ]
Is there some way to access an iterator value to do something like...
myset.erase( myset[member currently being evaluated].substr(0,1)=="F") ?
// unordered_set::erase
#include <iostream>
#include <string>
#include <unordered_set>
int main ()
{
std::unordered_set<std::string> myset =
{"USA","Canada","France","UK","Japan","Germany","Italy"};
myset.erase ( myset.begin() ); // erasing by iterator
myset.erase ( "France" ); // erasing by key
myset.erase ( myset.find("Japan"), myset.end() ); // erasing by range
std::cout << "myset contains:";
for ( const std::string& x: myset ) std::cout << " " << x;
std::cout << std::endl;
return 0;
}