C++ – How to convert vector to array

arrayscvector

How do I convert a std::vector<double> to a double array[]?

Best Answer

There's a fairly simple trick to do so, since the spec now guarantees vectors store their elements contiguously:

std::vector<double> v;
double* a = &v[0];