I was trying to take user input n
(cin >> n
) and using that n
to define the array size (arr[n]
). It works on other compilers, but on Visual Studio it is not working, so trying to find the root of the problem and is there a way around?
This is a hackerrank problem, my submission was successfully accepted, I've tried on multiple online and offline compilers, my code works, it's only on Visual Studio that I'm facing the issue.
int n;
cin >> n;
int arr[n]; //this line has the error
The error I'm getting is:
Error (active) E0028 expression must have a constant value Project2 D:\Code\C++\source\Project2\Source.cpp in line 9