-1

hello there i was writing a code in a compiler but my compiler had this error :"false expression must have a constant value" in one of the program lines i used other compilers but they didn't say this and i could write my program , but in visual studio 2022 it gives me the error the sample of the program is :

 stack<char> stack;
 queue<char> queue;
string str;
cin >> str;
char ch[str.length()];

the error is in the

char ch[str.length()];

i dont know how to fix this i would be glad if you guys help me in this

1 Answers1

1

Variable-length arrays is not C++ standard, see here. Because str.length() is known at runtime, but the size of the array has to be known at compile-time, this will cause an error.

You should use std::vector instead:

Replace:

char ch[str.length()];

With:

std::vector<char> ch(str.length());