Untitled
unknown
plain_text
a month ago
797 B
1
Indexable
Never
#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