原标题:vscode显示range-based 'for' loops are not allowed in C++98 mode的解决办法
原文来自:CSDN 原文链接:https://blog.csdn.net/weixin_41234001/article/details/101615996
在使用vscode写C++时,使用for范围的方法遍历vector时,程序编译报错,报错为:
range-based 'for' loops are not allowed in C++98 mode
测试代码如下:
#include<iostream>
#include<vector>
#include<string>
using namespace std;
int main(){
vector<int> ivec;
int number;
char flag='y';
while (cin>>number)
{
ivec.push_back(number);
cout<<"是否继续输入"<<endl;
cin>>flag;
if (flag=='y'||flag=='Y')
{
}else{
break;
}
}
//范围for
for (auto &i : ivec)
i *= i;
for (auto i : ivec)
cout<<i<<" ";
system("pause");
return 0;
}#include<iostream>
#include<vector>
#include<string>
using namespace std;
int main(){
vector<int> ivec;
int number;
char flag='y';
while (cin>>number)
{
ivec.push_back(number);
cout<<"是否继续输入"<<endl;
cin>>flag;
if (flag=='y'||flag=='Y')
{
}else{
break;
}
}
//范围for
for (auto &i : ivec)
i *= i;
for (auto i : ivec)
cout<<i<<" ";
system("pause");
return 0;
}
解决方法:
修改task.json配置文件,在"args”中加入"-std=c++11",保存文件,重新进行编译,即可解决问题
上面是我的task.json的对args设置的一些参数
免责声明:本文来自互联网新闻客户端自媒体,不代表本网的观点和立场。
合作及投稿邮箱:E-mail:editor@tusaishared.com