C++ Coding Errors

Hello, I am new to this forum and trying to teach myself how to code using C++. I donĀ“t know why when I try to build this code with Visual Studio 2019 it returns an error.

109 string options[noOfOptions];
110 for (int k = 0; k < noOfOptions; k++) {
111 getline(infile, option);
112 options[k] = option;


Error C3863-array type 'std::string [noOfOptions]' is not assignable 112
Error C2131-expression did not evaluate to a constant 109
Error active) E0028-expression must have a constant value 109

Message-see usage of 'noOfOptions' 109
Message-failure was caused by a read of a variable outside its lifetime 109



Last edited on
Please edit your post and add [code][/code] tags around your code. That's unreadable.

1
2
3
4
int noOfOptions;
infile >> noOfOptions;
getline(infile, temp);
string options[noOfOptions];
This is illegal. The size of a stack array must be a constant known at compile time. If you need an array of variable size you need to allocate it dynamically or use an STL container.
Topic archived. No new replies allowed.