How to loop through a list in C++

1 Answer

0 votes
#include <iostream>
#include <list>

int main()
{
    std::list<int> lst = { 3, 8, 6, 9, 7, 6, 2 };
 
    for (auto it = lst.begin(); it != lst.end(); it++) {
        std::cout << *it << ' ';
    }
}
 
 
 
/*
run:
 
3 8 6 9 7 6 2 
 
*/

 



answered Dec 18, 2024 by avibootz

Related questions

1 answer 96 views
1 answer 103 views
2 answers 94 views
1 answer 99 views
1 answer 152 views
4 answers 289 views
289 views asked Apr 22, 2023 by avibootz
1 answer 152 views
...