Sum two vector and store stl algorithm

Viewed 170

I have two vectors and I want to do something like

v2[i] = v1[i] +v2[i];

I have tried std::copy, but obviously that only do v2[i] = v1[i];

Is there any algorithm in the STL that performs this sum?

1 Answers

You can use std:::transform

std::transform(v1.begin(), v1.end(), v2.begin(), v2.begin(), std::plus<>());
Related