Visual Studio Code c ++ 11扩展警告 [英] Visual Studio Code c++11 extension warning

查看:104
本文介绍了Visual Studio Code c ++ 11扩展警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习c ++,并且正在为Mac使用Visual Studio代码.我使用Code Runner运行程序.我的问题是,当我使用c ++ 11中的诸如"auto"之类的变量声明时,Visual Studio代码会给我这样的警告,但是如果我尝试在Xcode或Eclipse上运行它,则不会:

I am in the process of learning c++ and I'm using visual studio code for Mac. I use Code Runner to run my program. My problem is that when I use something from c++11 like "auto" for variable declaration, visual studio code gives me a warning like this, but if I try running it on Xcode or Eclipse it doesn't:

warning: 'auto' type specifier is a C++11 extension [-Wc++11-extensions]
for(auto y: nstrVec)

这是必要的程序:

#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <numeric>
#include <sstream>

int main(){

std::vector<std::string> nstrVec(10);

std::string str("I'm a string");
nstrVec[0] = str;

std::cout << str.at(0) << "\n";
std::cout << str.front() << " " << str.back() << "\n";
std::cout << "Length " << str.length() << "\n";
// copies all characters after the fourth 
std::string str2(str, 4);

for(auto y: nstrVec)
    if(y != "")
        std::cout << y << "\n";

return 0;
}

这是c_cpp_proprerties.json文件:

And this is the c_cpp_proprerties.json file:

{
"configurations": [
    {
        "name": "Mac",
        "includePath": [
            "${workspaceFolder}/**",
                 "/System/Library/Frameworks/Kernel.framework/Versions/A/Headers"
        ],
        "defines": [],
        "macFrameworkPath": [
            "/System/Library/Frameworks",
            "/Library/Frameworks"
        ],
        "compilerPath": "/usr/bin/clang",
        "cStandard": "c11",
        "cppStandard": "c++17",
        "intelliSenseMode": "clang-x64"
    }
],
"version": 4
}

推荐答案

在VS代码中:

文件>>首选项>>设置>>扩展名

File>>Preference>>Settings>>Extensions

找到C_Cpp>默认:Cpp标准下拉菜单

find C_Cpp>Default:Cpp Standard drop down menu

将其设置为c ++ 11

set that to c++11

这篇关于Visual Studio Code c ++ 11扩展警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆