last element of a set in c++

#include <iostream>
#include <set>

int main() {
    std::set<int> mySet = {1, 2, 3, 4, 5};

    if (!mySet.empty()) {
        auto lastElement = *mySet.rbegin();
        std::cout << "The last element of the set is: " << lastElement << std::endl;
    } else {
        std::cout << "The set is empty." << std::endl;
    }

    return 0;
}