123456789101112131415161718
//copy int vector to int array #include <iostream> #include <vector> #include <cstddef> using namespace std; int main() { vector<int> ivec(5,2); const unsigned n=ivec.size(); int iarr[n]={}; size_t i=0; for(auto j:ivec) { iarr[i]=j; cout<<iarr[i]<<" "; i++; } }
int *iarr = new int[n]{};