Problem description

Today, I used the features of C++11 when writing C++ code, and found that VSCode can be compiled, but it will be red in the corresponding position, as shown in the picture below.

And the following warning is encountered during compilation:

C1.cpp:62:14: warning: 'auto' type specifier is a C++11 extension [-Wc++11-extensions]
        for (auto a : vec) 
Copy the code

Cause: VSCode cannot detect C++11 syntax according to compilation parameters, causing red and warning.

The solution

You can follow the following steps:

  • Click on the pinion in the C/C++ plug-in to download
  • Select the Extension Setting option
  • In the Compiler Args option, click Edit in Setting.json

Finally, add the following compilation parameters to the popup setting.json file:

{
    "C_Cpp.default.compilerArgs": [
        "-g",
		"${file}",
        "-std=c++11",
		"-o",
		"${fileDirname}/${fileBasenameNoExtension}"
    ]
}
Copy the code

At this point my problem is solved. If you have any questions, please leave a message and I will reply as soon as possible

Recommend knowledge

Please pay attention and love to me, study and communicate with me

included