vectors c++

#include <iostream>
#include <vector>

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

    // Step 2: Add elements to the vector using push_back
    myVector.push_back(10);
    myVector.push_back(20);
    myVector.push_back(30);

    // Step 3: Access elements using index
    std::cout << "Element at index 0: " << myVector[0] << std::endl;

    // Step 4: Get the size of the vector
    std::cout << "Vector size: " << myVector.size() << std::endl;

    // Step 5: Iterate through the vector using a loop
    std::cout << "Elements in the vector: ";
    for (int i = 0; i < myVector.size(); ++i) {
        std::cout << myVector[i] << " ";
    }
    std::cout << std::endl;

    // Step 6: Use iterators to access elements
    std::cout << "Elements using iterators: ";
    for (std::vector<int>::iterator it = myVector.begin(); it != myVector.end(); ++it) {
        std::cout << *it << " ";
    }
    std::cout << std::endl;

    // Step 7: Clear the vector
    myVector.clear();

    // Step 8: Check if the vector is empty
    std::cout << "Is vector empty? " << (myVector.empty() ? "Yes" : "No") << std::endl;

    return 0;
}