remove first occurrence of value from vector c++

#include <iostream>
#include <vector>

int main() {
    // Step 1: Create a vector and initialize it with values
    std::vector<int> myVector = {1, 2, 3, 4, 5};

    // Step 2: Specify the value to be removed
    int valueToRemove = 3;

    // Step 3: Find the iterator pointing to the first occurrence of the value
    auto it = std::find(myVector.begin(), myVector.end(), valueToRemove);

    // Step 4: Check if the value is found before attempting to erase
    if (it != myVector.end()) {
        // Step 5: Erase the element at the found iterator position
        myVector.erase(it);

        // Optional: Print the updated vector
        std::cout << "Vector after removing the first occurrence of " << valueToRemove << ": ";
        for (int element : myVector) {
            std::cout << element << " ";
        }
        std::cout << std::endl;
    } else {
        // Optional: Print a message if the value is not found
        std::cout << "Value " << valueToRemove << " not found in the vector." << std::endl;
    }

    return 0;
}