Is there any implemented method in the C++ library which allows you to sum the values of two vectors (of the same size and type of course)?
For example:
std::vector<int> a;//looks like this: 2,0,1,5,0
std::vector<int> b;//looks like this: 0,0,1,3,5
Now then adding their values together should look like this:
//2,0,2,8,5
The answer I'm expecting is either "No there isn't" or "yes" + method.
You can use std::transform
and std::plus<int>()
std::vector<int> a;//looks like this: 2,0,1,5,0
std::vector<int> b;//looks like this: 0,0,1,3,5
// std::plus adds together its two arguments:
std::transform (a.begin(), a.end(), b.begin(), a.begin(), std::plus<int>());
// a = 2,0,2,8,5
This form of std::transform
takes 5 arguments:
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