Elegant way to find keys with given prefix in std::map or elements in std::set

I think the solution you mentioned is already the most elegant. The KISS way loses a lot of performance, that is, checking the key each time:

while(prefixedBeginIt->first == prefix)
{
 //...
 ++prefixedBeginIt;
}

Thus I think calculating the next char is the best approach:

std::string firstAfterPrefix = prefix;
++firstAfterPrefix[firstAfterPrefix.length() - 1];
auto prefixedEndIt = myMap.lower_bound(firstAfterPrefix);