I want to convert a float vector to a float array in C++ 20. I searched online and found this solution:
#include <iostream>
#include <algorithm>
#include <vector>
int main()
{
std::vector<int> input({ 1, 2, 3, 4, 5 });
int arr[input.size()];
std::copy(input.begin(), input.end(), arr);
for (int i: arr) {
std::cout << i << ' ';
}
return 0;
}
But when I try to implement it, the compiler gives me an error saying that what's inside the brackets in the array declaration must be a constant expression.
Since when is this the case? I swear I've declared arrays in a similar manner in C++ before and it worked. And if you look online you'll see that everyone does this too, the example I posted seems to be the standard solution to my problem. So why does it give me an error?