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 164 views
164 views asked Dec 25, 2024 by avibootz
2 answers 262 views
262 views asked May 9, 2021 by avibootz
1 answer 255 views
1 answer 226 views
1 answer 180 views
180 views asked Jun 18, 2022 by avibootz
2 answers 374 views
1 answer 216 views
...