Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22113

Variable Length array forbidden in ISO C++ error in sublime text 3

$
0
0

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!


Viewing all articles
Browse latest Browse all 22113

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>