How to iterate through forward_list in C++

1 Answer

0 votes
#include <iostream>
#include <forward_list>

void print( std::forward_list<int> fl) {
    for (auto it = fl.begin(); it != fl.end(); ++it )
        std::cout << *it << ", ";
    
    std::cout << "\n";
}

int main() {
    std::forward_list<int> fl = {2, 5, 32, 9, 8, 7};

    print(fl);
}



/*
run:

2, 5, 32, 9, 8, 7, 

*/

 



answered Aug 2, 2020 by avibootz

Related questions

1 answer 88 views
88 views asked Dec 25, 2024 by avibootz
2 answers 166 views
166 views asked May 9, 2021 by avibootz
1 answer 166 views
1 answer 150 views
1 answer 117 views
117 views asked Jun 18, 2022 by avibootz
2 answers 249 views
1 answer 145 views
...