Program
#include <iostream>
#include <cstdlib>
#include <cstring>
using namespace std;
int main(int argc, char** argv)
{
if(argc < 2)
exit(1);
cout<<strtof(argv[1],NULL);
int SIZE = (int) (strtof(argv[1],NULL)/8);
int **arr = new int[SIZE][SIZE*4]();
for(int i = 0; i < SIZE; i++) {
for(int j = 0; j < SIZE*4; j++) {
cout<<arr[i][j];
}
}
return 0;
}
Input
32
Error
prog.cpp: In function ‘int main(int, char**)’: prog.cpp:13:39: error: array size in new-expression must be constant
int **arr = new int[SIZE][SIZE*4]();
^
prog.cpp:13:39: error: the value of ‘SIZE’ is not usable in a constant expression prog.cpp:12:9: note: ‘int SIZE’ is not const
int SIZE = (int) (strtof(argv[1],NULL)/8);
^~~~
Is there any other way, rather than using malloc or calloc to do this in C++11?