Hi all,
As a function argument I get a vector<double>& vec
(an output vector, hence non-const) with unknown length and values. I want to initialise this vector to a specific length n with all zeroes.
This will work
vec.clear();
vec.resize( n, 0.0 );
And this will work as well:
vec.resize( n );
vec.assign( n, 0.0 );
Is the second more efficient (because no memory deallocation/allocation is involved)? Is there a more efficient way to do this?