I recently changed my C++ compiler, and I am experiencing this strange error that says ISO C++ forbids variable length array. I distinctly remember that this error was not encountered by my previous compiler. Here is my code snippet that I wrote just to check the reliability of this new compiler.
#include <iostream>
using namespace std;
int main()
{
int n;
cin>>n;
int a[n];
for(int i=0;i<n;i++)
cin>>a[i];
for(int i=0;i<n;i++)
cout<<a[i]<<" ";
return 0;
}
In function 'int main()':
test.cpp:8:9: error: ISO C++ forbids variable length array 'a' [-Wvla]
int a[n]={0};
You see even when user is taking input in 'n', the compiler states that the array is having variable length. Suggestions regarding other compiler version are also welcome!
Aucun commentaire:
Enregistrer un commentaire