It is possible to initialise a vector from an array holding elements with the same type as vector, such as
double a[] ={ somevalues };
std::vector<double> vec(a, a+dimension)
I was wondering whether the other way around is possible or not without an explicit loop? Is that possible to initialise an array from a vector with a short cut like the one above, I guess not but let me ask …
No, it is not possible to do it at initialization, but you can use one algorithm from the STL:
Or alternatively:
The assert is to ensure that you don’t go beyond the size of the vector (which would cause undefined behavior), and limiting the copies (the 100 in the expressions) so that you don’t overflow the array either.