Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio Code c++11 extension warning

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)

This is the program if it's necessary:

#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;
}

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
}
like image 765
BONANDRINI CARLO Avatar asked Jun 26 '18 15:06

BONANDRINI CARLO


People also ask

Why extensions are not working in VS Code?

Views and more Actions click Disable All Installed Extensions then Enable All Extensions . Restart VSCode and it should be done; -) You can make sure again that the extensions are enabled.. Good Luck !

Why my C code is not working in VS Code?

Go to the menu Code > Preferences > Settings. In the User tab on the left panel, expand the Extensions section. Find and select Run Code Configuration. Find and check the box Run in Terminal.

Can VS Code extensions have malware?

They can contain malware, yes. When you download and run an extension, you are trusting it to do pretty much anything it wants with the permissions of your user. VS Code does not implement sandboxing (like browsers do), and the code is not much restricted.


2 Answers

In VS Code:

File>>Preference>>Settings>>Extensions

find C_Cpp>Default:Cpp Standard drop down menu

set that to c++11

Image of Option Window

like image 118
iamczar Avatar answered Sep 20 '22 00:09

iamczar


I had the same problem, but solved it using set vscode-user-settings <>

"clang.cxxflags": ["-std=c++14"]

vscode- user setting

like image 39
vic.zhang Avatar answered Sep 23 '22 00:09

vic.zhang