Engineer bro!

Fri Nov 12 2021 (2 years ago)

Engineer by mistake!

I am a software engineer by passion

The for_each function in C++ | STL

In this article, we'll see that how can we use the for_each function of C++.


for_each function is used to do some operations for every element in the range [first,last)[first, last).

Table of contents


int main() {
    vector<int> v{41, 61, 81};
    auto print = [](int n) { 
        cout << " " << n; 

    for_each(v.begin(), v.end(), print);
    return 0;


Thank You ❤️


© 2021 dsabyte. All rights reserved