首页 > 解决方案 > 在 Mac 的 Visual Studio 代码中删除“自动”类型说明符和基于范围的循环 C++ 扩展警告

问题描述

我是 C++ 的初学者。我正在为 Mac 使用 Visual Studio 代码。我的问题是,每当我使用“auto”进行变量声明时,Visual Studio 代码都会给我一个警告,如下所示:

警告:'auto' 类型说明符是 C++11 扩展 [-Wc++11-extensions]

我尝试在用户设置中将 C_Cpp Standard> Default: Cpp Standard 更改为 c++11,但它仍然给我一个警告。

如果有必要,这是我的代码

#include<iostream>
using namespace std;
int main(){
    vector<int> numbers;
    char selection;

    do
    {
        cout<<"\nP - Print numbers"<<endl;
        cout<<"A - Add a number"<<endl;
        cout<<"M - Display mean of the numbers"<<endl;
        cout<<"S - Display the smallest number"<<endl;
        cout<<"L - Display the largest number"<<endl;
        cout<<"Q - Quit"<<endl;

        cout<<"Enter your choice:"<<endl;
        cin>>selection;
    } 
    cout<<endl;

    if(selection == 'p' || selection == 'P'){
        if(numbers.size() == 0){
            cout<<"[] - the list is empty"<<endl;
        }
        else{
            cout<<"[ ";
            for(auto num: numbers){
                cout<< num << " ";
                cout<< "]" <<endl;
            }
        }
    }while (selection != 'q' || selection != 'Q');
    return 0;
}

标签: c++ios

解决方案


推荐阅读