how to fill vector from inputs c++

#include <iostream>
#include <vector>

int main() {
    std::vector<int> myVector;  // Step 1: Declare a vector to store integers

    int size;                   // Step 2: Declare a variable to store the size of the vector
    std::cout << "Enter the size of the vector: ";
    std::cin >> size;           // Step 3: Read the size of the vector from the user

    myVector.resize(size);      // Step 4: Resize the vector to accommodate the specified size

    std::cout << "Enter " << size << " elements separated by spaces: ";

    for (int i = 0; i < size; ++i) {
        std::cin >> myVector[i]; // Step 5: Read elements from the user and store them in the vector
    }

    // Display the elements in the vector
    std::cout << "Vector elements: ";
    for (int i = 0; i < size; ++i) {
        std::cout << myVector[i] << " ";
    }

    return 0;
}