sort(arr.begin(),arr.end(),comparator); code example Example: how to sort in descending order in c++ sort(str.begin(), str.end(), greater<int>()); cout<<str;