一 、现象
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
int arr[10] = { 1,2,3,4,5,6,7,8,9,10 };
for (int e : arr)
{
cout << e << " ";
}
cout << endl;
return 0;
}
范围for 是在 c++11 中实现的 ,默认编译就会报错,那怎么解决呢?
二 、方法如下
菜单中,点击:工具->编译选项,打开
出现这样一个窗口:
勾选【编译时加入一下命令】,
然后在下方的编译框中加入:
-std=c++11
要想支持其他C++的标准也是一样的方法。
-std=c++14
-std=c++17
-std=c++20 等