How to initialize and print a forward_list with ints in C++

1 Answer

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

using std::forward_list;
using std::cout;

void printList(const forward_list<int>& flist)
{
	for (auto elem : flist) {
		cout << elem << ' ';
	}
	cout << std::endl;
}

int main()
{

	forward_list<int> flist = { 1, 2, 3, 4, 5 };

	printList(flist);

	return 0;
}

/*
run:

1 2 3 4 5

*/

 



answered Jan 6, 2018 by avibootz
edited Jan 7, 2018 by avibootz

Related questions

1 answer 169 views
1 answer 191 views
1 answer 205 views
205 views asked Aug 2, 2020 by avibootz
1 answer 164 views
164 views asked Aug 2, 2020 by avibootz
4 answers 338 views
2 answers 223 views
1 answer 169 views
...