How to iterate over array using STL for_each in C++

1 Answer

0 votes
#include <iostream>
#include <array>

using std::cout;
using std::endl;
using std::array;

int main()
{
	array<int, 5> arr = { 45, 32, 54, 21, 9 };

	for_each(arr.begin(), arr.end(), [](const int & element) {
		cout << element << ", ";
	});
	cout << endl;

	return 0;
}


/*
run:

45, 32, 54, 21, 9,

*/

 



answered Feb 3, 2018 by avibootz
edited Feb 3, 2018 by avibootz

Related questions

...