I'm using Visual Studio Code to compile C++ programs and it works for most C++ programs as it compiles it using g++
command. However, I am facing difficulty in compiling c++11
programs using it.
When I try compiling C++11 programs, the compiler command g++
tries to compile it using default C++98 Standard and this results in errors.
I am aware that using g++ -std=c++11
, we can compile C++11 programs using g++
and it works fine when I use it in my cmd
as:
g++ -std=c++11 some_program.cpp
I wish I could tweak some setting in Visual Studio Code and change the compiler command from g++
to g++ -std=c++11
so that I could compile programs by just hitting the run code
button. However, I'm not able to find one. Please help me out if there are alternate ways to get my program compiled.
Currently, I'm getting errors as:
some_program.cpp: In function 'int main()':
some_program.cpp:12:33: error: in C++98 'A' must be initialized by constructor, not by '{...}' vector A = { 11,2,3,14 };
The snippets are correct and have been tested with online compilers using C++11. Here, it is trying to compile using C++98
as seen in the error.
Go to Settings
> User Settings
In here, search for Run Code Configuration
:
Under this menu, find:
"code-runner.executorMap"
Edit this Setting by adding it to User Setting as below for C++11 support:
"code-runner.executorMap":{
"cpp": "cd $dir && g++ -std=c++11 $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
},
OR
Edit this Setting by adding it to User Setting as below for C++17 support:
"code-runner.executorMap":{
"cpp": "cd $dir && g++ -std=c++17 $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
},
Hope this helps !
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With