error: 'listOfColors' was not declared in this scope
error: 'listOfColors' was not declared in this scope
我是 C++ 的新手,我不明白为什么我会收到 not declared
错误:
int main(){
string listOfColors[5] = {"red","blue","green","yellow","magenta"};
for(int i = 0;i < sizeof listofColors;i++){
cout << listofColors[i] << "\n";
}
return 0;
}
到目前为止,这是我第一次使用数组,所以我可能只是没有正确声明它。我也事先在主函数之前有数组声明。
您将变量声明为 listOfColors
(大写 "O"),然后在 for
循环中将其用作 listofColors
。您需要做的就是在使用变量时将 "O" 大写。
我是 C++ 的新手,我不明白为什么我会收到 not declared
错误:
int main(){
string listOfColors[5] = {"red","blue","green","yellow","magenta"};
for(int i = 0;i < sizeof listofColors;i++){
cout << listofColors[i] << "\n";
}
return 0;
}
到目前为止,这是我第一次使用数组,所以我可能只是没有正确声明它。我也事先在主函数之前有数组声明。
您将变量声明为 listOfColors
(大写 "O"),然后在 for
循环中将其用作 listofColors
。您需要做的就是在使用变量时将 "O" 大写。