-2

Total c++ newbie here.

I have a problem, where I can not assign the number of character in a string to an array size, like so..

string outStr;
ifstream input("read.txt");
getline(input, outStr);

int const n = outStr.length();
int arr[n];

error msg --> expression must have a constant value. although i have declared the "const"

Thanks in advance✌.

Fa3o
  • 13
  • 6

1 Answers1

1

C++ does not support Variable Length Arrays. Use a std::vector instead.

Jesper Juhl
  • 30,449
  • 3
  • 47
  • 70