资源经验分享vscode显示range-based 'for' loops are not allowed in C++98 mode的解决办法

vscode显示range-based 'for' loops are not allowed in C++98 mode的解决办法

2019-09-29 | |  322 |   0

原标题: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",保存文件,重新进行编译,即可解决问题

 

b4.png

 

上面是我的task.json的对args设置的一些参数


免责声明:本文来自互联网新闻客户端自媒体,不代表本网的观点和立场。

合作及投稿邮箱:E-mail:editor@tusaishared.com

上一篇:迭代列表不要For循环,这是Python列表推导式最基本的概念

下一篇:一分钟了解:a*算法

用户评价
全部评价

热门资源

  • Python 爬虫(二)...

    所谓爬虫就是模拟客户端发送网络请求,获取网络响...

  • TensorFlow从1到2...

    原文第四篇中,我们介绍了官方的入门案例MNIST,功...

  • TensorFlow从1到2...

    “回归”这个词,既是Regression算法的名称,也代表...

  • 机器学习中的熵、...

    熵 (entropy) 这一词最初来源于热力学。1948年,克...

  • TensorFlow2.0(10...

    前面的博客中我们说过,在加载数据和预处理数据时...