VC++ is giving an error on below code:
#include <vector>
#include <iostream>
int main()
{
std::vector<int> a;
a.push_back(10);
a.push_back(20);
a.push_back(30);
int arr[a.size()];
std::copy(a.begin(), a.end(), arr);
for(int index = 0 ; index < a.size(); index++)
{
std::cout << " The value is " << arr[index] << std::endl;
}
}
It errors out at the integer array declaration stating that the value of variable 'a' cannot be used as constant?
How can we resolve the issue where my objective is to transfer content of vector into a 'C' style array?
int *pointer to pass to a function, you can usea.data()auto copy_a = a;will get you the very same thing, without any hassle, headaches or having to worry about the need to manuallydelete[]anything.