Hi there, I recently made a program using Dev C++ and it would compile and run just as I wanted it. I then imported the .cpp files into Visual Studio 2010 Ultimate and went to recompile except it is not compiling the following part of a function. The code in question is:
1 2 3 4 5 6 7
string Descrambler::order(string word) //descramble words and check them
{
string input = word;
int len = word.length(); //length of string
int num[len]; //how many chars there are
...
This would be fine in Dev C++. However in VS it gives the following error:
1 IntelliSense: expression must have a constant value
This seems odd and I am unsure of what I am doing wrong. I changed it to the following but it still gave the same error:
1 2 3
string input = word;
int len = 2; //length of string
int num[len];
I see no reason in why this would work fine in Dev C++ but not in VS. any help would be greatly appreciated thank you.
This isn't legal C++. In C++, a stack allocated array must have a constant as its size. And you shouldn't use Dev-C++ because it hasn't been updated in over 5 years.
The devc++ isn't more flexible, you can do the same things in standard c++. You just do it a bit differently. In C++ you can just use vectors, or dynamic allocation as already pointed out.
New throws an exception when the memory allocation fails, alone because of that it's better.