Hi,
I'm using the vector container to store an array of doubles. Is there any quick way of multiplying each element in my vector by some scalar without using a loop.
For example:
vector<double> Array(10,1);
will initialise an array of 10 doubles with initial value 1. To multiply this array by 0.5 I would write:
for(unsigned int i=0; i<Array.size(); i++)
Array[i] = 0.5*Array[i];
Is there there another way? I have used valarray which overloads the '*' operator so that:
Array = 0.5 * Array;
is valid but I'd rather not use valarray as it seems the vector container is a more standard approach for manipulating arrays.
Thanks!