<分区>
好的,当我尝试根据用户输入打印某些内容时出现错误。很标准的东西,对吧?因此,如果程序能够正常运行,用户将输入六个单词或短语,这些单词或短语将存储在名为 PhrasesAndWords 的字符串中。然后,通过创建一个 while 循环,使用计数器作为 switch 语句中的索引来测试数组的每个部分。嗯,显然,这不起作用,因为它不是常量表达式或 constexpr。但是,变量不能是常量表达式,因为那样会导致无限循环。顺便说一句,这是错误:
C:\Users\henry\Desktop\NotTheActualPathForThisProject\main.cpp|34|错误:开关数量不是整数|
Aaand 这是我写的代码(虽然我已经去掉了不相关的变量等):
int main() {
string phrasesAndWords[6];
cin >> phrasesAndWords[0] >> phrasesAndWords[1] >> phrasesAndWords[2] >> phrasesAndWords[3] >> phrasesAndWords[4] >> phrasesAndWords[5]; // Recieve input
int counter = 0;
while (counter < 6) {
switch(phrasesAndWords[counter]) {
case "RandomString":
print("That sure was quite random. \n")
default:
print("I don't understaahnd... \n")
};
counter++;
};
};