c++ how to skip the last element of vector

#include <iostream>
#include <vector>

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

    if (!myVector.empty()) {
        myVector.pop_back();
    }

    for (const auto& element : myVector) {
        std::cout << element << " ";
    }

    return 0;
}