Visual Studio Code c 11 扩展警告

新手上路,请多包涵

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

 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 文件:

 {
"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
}

原文由 BONANDRINI CARLO 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 672
1 个回答

在 VS 代码中:

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

找到 C_Cpp>Default:Cpp Standard 下拉菜单

将其设置为 c++11

选项窗口的图像

原文由 iamczar 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题