Reputation: 823
I have one vector::
static const std::vector<float> vector1
and one reference of a vector:
std::vector<float> const& vector2
I need to multiply the values of these vectors with each other and store them in a new vector.
For example:
result[0]=vector1[0]*vector2[0]
result[1]=vector1[1]*vector2[1]
Then I need to give this vector to a method which only accepts:
std::vector<float> const& result
How do I do this in C++?
Upvotes: 0
Views: 885
Reputation: 52591
std::vector<float> result;
std::transform(
vector1.begin(), vector1.end(),
vector2.begin(),
std::back_inserter(result), std::multiplies<float>());
CallMethodThatTakesReferenceToVector(result);
Upvotes: 5