Engineer bro!

Fri Nov 12 2021 (1 year 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

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

Example

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

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


C++