C++ vector Deleting a Single Value Question

Question

Write a program that defines a vector of integers.

Erase the second element from the vector.

Print out the vector content using the range-based loop.

You can use the following code structure:

#include <iostream> 

int main() /* ww  w.j  a  v a2  s. c o m*/
{ 

} 

#include <iostream> 
#include <vector> 
int main() 
{ 
    std::vector<int> v = { 10, 5, 8, 4, 1, 2 }; 
    v.erase(v.begin() + 1); // erase the second element which is 5 

    for (auto el : v) 
    { 
        std::cout << el << '\n'; 
    } 
} 



PreviousNext

Related