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

1 Answer

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

 



answered Apr 11, 2020 by avibootz
edited Apr 21, 2024 by avibootz

Related questions

1 answer 214 views
1 answer 193 views
1 answer 175 views
3 answers 414 views
1 answer 129 views
129 views asked Jan 25, 2018 by avibootz
1 answer 190 views
...