Hello, I'm trying to figure out how to sort a vector from Z to A. Or even if I was dealing with numbers how to go from Greatest to Least in integer values?
I figured out A-Z in this code here. I also know how to sort numbers from Least to Greatest. I don't understand sorting the other way around. Any help would be appreciated! Thanks!
If you consult documentation for the std::sort function, you'll see that there are several versions of the function and one of them takes, as it's third argument, a comparison function/object.
std::sort(FirstNames.begin(), FirstNames.end());
is equivalent to std::sort(FirstNames.begin(), FirstNames.end(), std::less<std::string>{});
Any guess as to what std::sort(FirstNames.begin(), FirstNames.end(), std::greater<std::string>{});
will do?
Header file required for std::less/std::greater is <functional>