How to remove the first element from a vector in C++

1 Answer

0 votes
#include <iostream>
#include <vector>
 
void printVector(std::vector<int> const &v) {
    for (auto const &n: v) {
        std::cout << n << " ";
    }
}
  
int main ()
{
    std::vector<int> v = { 5, 2, 7, 1, 9, 3 };
  
    v.erase(v.begin());
    
    printVector(v);
  
    return 0;
}
  
  
  
  
/*
run:
  
2 7 1 9 3 
   
*/

 



answered Apr 10, 2020 by avibootz

Related questions

1 answer 170 views
2 answers 286 views
2 answers 182 views
182 views asked May 1, 2018 by avibootz
2 answers 219 views
1 answer 159 views
...