How to convert vector to array

ganuke picture ganuke · May 27, 2010 · Viewed 364.9k times · Source

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

Answer

Michael Mrozek picture Michael Mrozek · May 27, 2010

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];