I was wondering if there is any way to print elements of vector only with using algorithm and/or functional library. I've done it with std::for_each() but I still need to use lambda function (and with my own named function), is there any way to avoid it? Here is my line of code that I need to replace with that new version:
std::for_each(v.begin(),v.end(), [](int n) { std::cout<<n<<std::endl;});
Thank You.
This version doesn't need a lambda:
std::copy(v.begin(), v.end(),
std::ostream_iterator<int>(std::cout, "\n"));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With