Calling a Function on Every Element in a Container with for_each algorithm - C++ STL Algorithm

C++ examples for STL Algorithm:for_each

Description

Calling a Function on Every Element in a Container with for_each algorithm

Demo Code

#include <algorithm>
#include <cinttypes>
#include <iostream>
#include <vector>

using namespace std;

int main(int argc, char* argv[])
{
    vector<int32_t> myVector {1,2,3,4,5};
    for_each(myVector.begin(), myVector.end(),
        [](int32_t value)
        {//from   ww w  . j  a  va  2  s  . c  o m
            cout << value << endl;
        });

    return 0;
}

Result


Related Tutorials