Untitled

mail@pastecode.io avatar
unknown
plain_text
5 months ago
797 B
1
Indexable

#include <iostream>
#include <vector>

int main() {
    // Step 1: Initialize the vector
    std::vector<int> numbers = {1, 2, 3, 4, 5};

    // Step 2: Print the contents of the vector
    std::cout << "Initial vector: ";
    for(int num : numbers) {
        std::cout << num << " ";
    }
    std::cout << std::endl;

    // Step 3: Add the number 6 to the end of the vector
    numbers.push_back(6);
    std::cout << "After adding 6: ";
    for(int num : numbers) {
        std::cout << num << " ";
    }
    std::cout << std::endl;

    // Step 4: Remove the first element from the vector
    numbers.erase(numbers.begin());
    std::cout << "After removing the first element: ";
    for(int num : numbers) {
        std::cout << num << " ";
    }
    std::cout << std::endl;

    return 0;
}
Leave a Comment