問題描述
我正在學習 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) << "
";
std::cout << str.front() << " " << str.back() << "
";
std::cout << "Length " << str.length() << "
";
// copies all characters after the fourth
std::string str2(str, 4);
for(auto y: nstrVec)
if(y != "")
std::cout << y << "
";
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 Code 中:
In VS Code:
文件>>首選項>>設置>>擴展
File>>Preference>>Settings>>Extensions
find C_Cpp>默認:Cpp 標準下拉菜單
find C_Cpp>Default:Cpp Standard drop down menu
將其設置為 c++11
set that to c++11
這篇關于Visual Studio Code c++11 擴展警告的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!