So I would like to create an array in a function with the size set by a number coming in as the parameter. Here is an example:
void temp_arr ( const int array_size ) {
int temp_arr[array_size]; //ERROR array_size needs to be a constant value
//Then do something with the temp arr
}
Even if the parameter is a const int, it will not work. I would like to not use a global const and not use vectors. I am just curious as I am learning C++. I would like for it to make it so that the array size is different each time the function is called. Is there a solution to this or am I to create a const variable and the array before the function is called?
int* temp_arr = new int[array_size]; ... delete[] temp_arr;std::vectorisn't C++? What is it withvectorwhy so many beginners think they shouldn't or can't use it?