运行 ❯
获取您
自己的
网站
×
更改方向
更改主题,深色/浅色
前往 Spaces
#include <iostream> #include <string> using namespace std; int main() { string cars[3] = {"Volvo", "BMW", "Ford"}; // An array with 3 elements // Trying to add another element (a fourth element) to the cars array will result in an error cars[3] = "Mazda"; for (string car : cars) { cout << car << "\n"; } return 0; }
main.cpp:9:3: 警告:数组索引 3 超出了数组的范围(包含 3 个元素)[-Warray-bounds]
cars[3] = "Mazda";
^