#includeint main() { std::vector nums = {1, 2, 3, 4, 5}; nums.erase(nums.begin() + 2); // removes the third element (3) return 0; }
#includeIn this example, we create a vector of integers and then erase elements 2, 3, and 4 using the iterators for the beginning and end of the range. Both of these examples use the standard library package "vector" to create and manipulate vectors of integers.int main() { std::vector nums = {1, 2, 3, 4, 5}; nums.erase(nums.begin() + 1, nums.begin() + 4); // removes elements 2, 3, and 4 return 0; }