C++ Error: range-based ‘for‘ loops are not allowed in C++98 mode

    科技2022-07-14  167

    #include<iostream> using namespace std;//打开c++标准库的头文件 int main() { int arr[10] = {1,2,3,4,5,6,7,8,9,0}; //for(int i = 0;i<10;i++) //{ //int j = i+1; //cout <<j<<endl; // cout <<arr[i]<<endl; // } for (int nVal : arr) //自动遍历arr这个数组 ,把arr[i]赋值给nval; { cout <<nVal<<" "; } return 0; }

    C++遇到这种问题,一般出现在循环里面,通过遍历的时候,就会出现错误;编辑提示错误:[Error] range-based ‘for’ loops are not allowed in C++98 mode;

    提示编译器不支持C++11!!! 解决办法: 我一般用的编辑器是Dev-C++,所以说我的解决步骤如下: 软件上面找到—》tool—》》Compiler options----》》在Compiler set to configure选择 TDM-GCC 4.9.2 64-bit Release–》》,如下图所示; 等一切操作完成,然后在编译或发现错误消失了。 C++新手,欢迎大家指教!

    Processed: 0.019, SQL: 8