VS code - Hide build/echo task for cpp - c++

I'm using VS Code for running c++ code.
Whenever I Ctrl + Shift + B to build my .cpp file, an 'echo' tab pops up, which makes the entire bottom panel appear and then I am asked to "Terminal will be reused by tasks, press any key to close it."
I don't want the tab or the panel to pop up at all and want the entire build process to happen in silence, nothing pops up.
This is my tasks.json file
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "echo",
"type": "shell",
"command": "gcc",
"args":[
"main.cpp","-lstdc++","-o" ,"main.exe"
],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}

This can be configured using "presentation": {...}. Following worked for me:
{
"version": "2.0.0",
"tasks": [
{
"label": "Test task",
"type": "shell",
"command": "echo Hello world",
"presentation": {
"echo": true,
"reveal": "never",
"showReuseMessage": false,
}
}
]
}

Solved by downgrading VSCode to 1.60: https://code.visualstudio.com/updates/v1_60

Related

Using the g++ compiler in VS Code [duplicate]

Microsoft's Visual Studio Code editor is quite nice, but it has no default support for building C++ projects.
How do I configure it to do this?
There is a much easier way to compile and run C++ code, no configuration needed:
Install the Code Runner Extension
Open your C++ code file in Text Editor, then use shortcut Ctrl+Alt+N, or press F1 and then select/type Run Code, or right click the Text Editor and then click Run Code in context menu, the code will be compiled and run, and the output will be shown in the Output Window.
Moreover you could update the config in settings.json using different C++ compilers as you want, the default config for C++ is as below:
"code-runner.executorMap": {
"cpp": "g++ $fullFileName && ./a.out"
}
The build tasks are project specific. To create a new project, open a directory in Visual Studio Code.
Following the instructions here, press Ctrl + Shift + P, type Configure Tasks, select it and press Enter.
The tasks.json file will be opened. Paste the following build script into the file, and save it:
{
"version": "0.1.0",
"command": "make",
"isShellCommand": true,
"tasks": [
{
"taskName": "Makefile",
// Make this the default build command.
"isBuildCommand": true,
// Show the output window only if unrecognized errors occur.
"showOutput": "always",
// Pass 'all' as the build target
"args": ["all"],
// Use the standard less compilation problem matcher.
"problemMatcher": {
"owner": "cpp",
"fileLocation": ["relative", "${workspaceRoot}"],
"pattern": {
"regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
"file": 1,
"line": 2,
"column": 3,
"severity": 4,
"message": 5
}
}
}
]
}
Now go to menu File → Preferences → Keyboard Shortcuts, and add the following key binding for the build task:
// Place your key bindings in this file to overwrite the defaults
[
{ "key": "f8", "command": "workbench.action.tasks.build" }
]
Now when you press F8 the Makefile will be executed, and errors will be underlined in the editor.
A makefile task example for new 2.0.0 tasks.json version.
In the snippet below some comments I hope they will be useful.
{
"version": "2.0.0",
"tasks": [
{
"label": "<TASK_NAME>",
"type": "shell",
"command": "make",
// use options.cwd property if the Makefile is not in the project root ${workspaceRoot} dir
"options": {
"cwd": "${workspaceRoot}/<DIR_WITH_MAKEFILE>"
},
// start the build without prompting for task selection, use "group": "build" otherwise
"group": {
"kind": "build",
"isDefault": true
},
"presentation": {
"echo": true,
"reveal": "always",
"focus": false,
"panel": "shared"
},
// arg passing example: in this case is executed make QUIET=0
"args": ["QUIET=0"],
// Use the standard less compilation problem matcher.
"problemMatcher": {
"owner": "cpp",
"fileLocation": ["absolute"],
"pattern": {
"regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
"file": 1,
"line": 2,
"column": 3,
"severity": 4,
"message": 5
}
}
}
]
}
Here is how I configured my VS for C++
Make sure to change appropriete paths to where your MinGW installed
launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "C++ Launch (GDB)",
"type": "cppdbg",
"request": "launch",
"targetArchitecture": "x86",
"program": "${workspaceRoot}\\${fileBasename}.exe",
"miDebuggerPath":"C:\\mingw-w64\\bin\\gdb.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceRoot}",
"externalConsole": true,
"preLaunchTask": "g++"  
}
]
}
tasks.json
{
"version": "0.1.0",
"command": "g++",
"args": ["-g","-std=c++11","${file}","-o","${workspaceRoot}\\${fileBasename}.exe"],
"problemMatcher": {
"owner": "cpp",
"fileLocation": ["relative", "${workspaceRoot}"],
"pattern": {
"regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
"file": 1,
"line": 2,
"column": 3,
"severity": 4,
"message": 5
}
}
}
c_cpp_properties.json
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceRoot}",
"C:/mingw-w64/lib/gcc/x86_64-w64-mingw32/7.2.0/include/c++",
"C:/mingw-w64/lib/gcc/x86_64-w64-mingw32/7.2.0/include/c++/x86_64-w64-mingw32",
"C:/mingw-w64/lib/gcc/x86_64-w64-mingw32/7.2.0/include/c++/backward",
"C:/mingw-w64/lib/gcc/x86_64-w64-mingw32/7.2.0/include",
"C:/mingw-w64/lib/gcc/x86_64-w64-mingw32/7.2.0/include/c++/tr1",
"C:/mingw-w64/x86_64-w64-mingw32/include"
],
"defines": [
"_DEBUG",
"UNICODE",
"__GNUC__=6",
"__cdecl=__attribute__((__cdecl__))"
],
"intelliSenseMode": "msvc-x64",
"browse": {
"path": [
"${workspaceRoot}",
"C:/mingw-w64/lib/gcc/x86_64-w64-mingw32/7.2.0/include/c++",
"C:/mingw-w64/lib/gcc/x86_64-w64-mingw32/7.2.0/include/c++/x86_64-w64-mingw32",
"C:/mingw-w64/lib/gcc/x86_64-w64-mingw32/7.2.0/include/c++/backward",
"C:/mingw-w64/lib/gcc/x86_64-w64-mingw32/7.2.0/include",
"C:/mingw-w64/lib/gcc/x86_64-w64-mingw32/7.2.0/include/c++/tr1",
"C:/mingw-w64/x86_64-w64-mingw32/include"
]
},
"limitSymbolsToIncludedHeaders": true,
"databaseFilename": ""
}
],
"version": 3
}
Reference:
C/C++ for VS Code
c_cpp_properties.json template
To Build/run C++ projects in VS code , you manually need to configure tasks.json file which is in .vscode folder in workspace folder .
To open tasks.json , press ctrl + shift + P , and type Configure tasks , and press enter, it will take you to tasks.json
Here i am providing my tasks.json file with some comments to make the file more understandable , It can be used as a reference for configuring tasks.json , i hope it will be useful
tasks.json
{
"version": "2.0.0",
"tasks": [
{
"label": "build & run", //It's name of the task , you can have several tasks
"type": "shell", //type can be either 'shell' or 'process' , more details will be given below
"command": "g++",
"args": [
"-g", //gnu debugging flag , only necessary if you want to perform debugging on file
"${file}", //${file} gives full path of the file
"-o",
"${workspaceFolder}\\build\\${fileBasenameNoExtension}", //output file name
"&&", //to join building and running of the file
"${workspaceFolder}\\build\\${fileBasenameNoExtension}"
],
"group": {
"kind": "build", //defines to which group the task belongs
"isDefault": true
},
"presentation": { //Explained in detail below
"echo": false,
"reveal": "always",
"focus": true,
"panel": "shared",
"clear": false,
"showReuseMessage": false
},
"problemMatcher": "$gcc"
},
]
}
Now , stating directly from the VS code tasks documentation
description of type property :
type: The task's type. For a custom task, this can either be shell or process. If shell is specified, the command is interpreted
as a shell command (for example: bash, cmd, or PowerShell). If
process is specified, the command is interpreted as a process to
execute.
The behavior of the terminal can be controlled using the
presentation property in tasks.json . It offers the following properties:
reveal: Controls whether the Integrated Terminal panel is brought to front. Valid values are:
- always - The panel is always brought to front. This is the default
- never - The user must explicitly bring the terminal panel to the front using the
View > Terminal command (Ctrl+`).
- silent - The terminal panel is brought to front only if the output is not scanned for errors and warnings.
focus: Controls whether the terminal is taking input focus or not. Default is false.
echo: Controls whether the executed command is echoed in the terminal. Default is true.
showReuseMessage: Controls whether to show the "Terminal will be reused by tasks, press any key to close it" message.
panel: Controls whether the terminal instance is shared between task runs. Possible values are:
- shared: The terminal is shared and the output of other task runs are added to the same terminal.
- dedicated: The terminal is dedicated to a specific task. If that task is executed again, the terminal is reused. However, the
output of a different task is presented in a different terminal.
- new: Every execution of that task is using a new clean terminal.
clear: Controls whether the terminal is cleared before this task is run. Default is false.
Out of frustration at the lack of clear documentation,
I've created a Mac project on github that should just work (both building and debugging):
vscode-mac-c-example
Note that it requires XCode and the VSCode Microsoft cpptools extension.
I plan to do the same for Windows and linux (unless Microsoft write decent documentation first...).
First of all, goto extensions (Ctrl + Shift + X) and install 2 extensions:
Code Runner
C/C++
Then, then reload the VS Code and select a play button on the top of the right corner your program runs in the output terminal. You can see output by Ctrl + Alt + N.
To change other features goto user setting.
The basic problem here is that building and linking a C++ program depends heavily on the build system in use. You will need to support the following distinct tasks, using some combination of plugins and custom code:
General C++ language support for the editor. This is usually done using ms-vscode.cpptools, which most people expect to also handle a lot of other stuff, like build support. Let me save you some time: it doesn't. However, you will probably want it anyway.
Build, clean, and rebuild tasks. This is where your choice of build system becomes a huge deal. You will find plugins for things like CMake and Autoconf (god help you), but if you're using something like Meson and Ninja, you are going to have to write some helper scripts, and configure a custom "tasks.json" file to handle these. Microsoft has totally changed everything about that file over the last few versions, right down to what it is supposed to be called and the places (yes, placeS) it can go, to say nothing of completely changing the format. Worse, they've SORT OF kept backward compatibility, to be sure to use the "version" key to specify which variant you want. See details here:
https://code.visualstudio.com/docs/editor/tasks
...but note conflicts with:
https://code.visualstudio.com/docs/languages/cpp
WARNING: IN ALL OF THE ANSWERS BELOW, ANYTHING THAT BEGINS WITH A "VERSION" TAG BELOW 2.0.0 IS OBSOLETE.
Here's the closest thing I've got at the moment. Note that I kick most of the heavy lifting off to scripts, this doesn't really give me any menu entries I can live with, and there isn't any good way to select between debug and release without just making another three explicit entries in here. With all that said, here is what I can tolerate as my .vscode/tasks.json file at the moment:
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "build project",
"type": "shell",
"command": "buildscripts/build-debug.sh",
"args": [],
"group": {
"kind": "build",
"isDefault": true
},
"presentation": {
// Reveal the output only if unrecognized errors occur.
"echo": true,
"focus": false,
"reveal": "always",
"panel": "shared"
},
// Use the standard MS compiler pattern to detect errors, warnings and infos
"options": {
"cwd": "${workspaceRoot}"
},
"problemMatcher": {
"owner": "cpp",
"fileLocation": ["relative", "${workspaceRoot}/DEBUG"],
"pattern": {
"regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
"file": 1,
"line": 2,
"column": 3,
"severity": 4,
"message": 5
}
}
},
{
"label": "rebuild project",
"type": "shell",
"command": "buildscripts/rebuild-debug.sh",
"args": [],
"group": {
"kind": "build",
"isDefault": true
},
"presentation": {
// Reveal the output only if unrecognized errors occur.
"echo": true,
"focus": false,
"reveal": "always",
"panel": "shared"
},
// Use the standard MS compiler pattern to detect errors, warnings and infos
"options": {
"cwd": "${workspaceRoot}"
},
"problemMatcher": {
"owner": "cpp",
"fileLocation": ["relative", "${workspaceRoot}/DEBUG"],
"pattern": {
"regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
"file": 1,
"line": 2,
"column": 3,
"severity": 4,
"message": 5
}
}
},
{
"label": "clean project",
"type": "shell",
"command": "buildscripts/clean-debug.sh",
"args": [],
"group": {
"kind": "build",
"isDefault": true
},
"presentation": {
// Reveal the output only if unrecognized errors occur.
"echo": true,
"focus": false,
"reveal": "always",
"panel": "shared"
},
// Use the standard MS compiler pattern to detect errors, warnings and infos
"options": {
"cwd": "${workspaceRoot}"
},
"problemMatcher": {
"owner": "cpp",
"fileLocation": ["relative", "${workspaceRoot}/DEBUG"],
"pattern": {
"regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
"file": 1,
"line": 2,
"column": 3,
"severity": 4,
"message": 5
}
}
}
]
}
Note that, in theory, this file is supposed to work if you put it in the workspace root, so that you aren't stuck checking files in hidden directories (.vscode) into your revision control system. I have yet to see that actually work; test it, but if it fails, put it in .vscode. Either way, the IDE will bitch if it isn't there anyway. (Yes, at the moment, this means I have been forced to check .vscode into subversion, which I'm not happy about.) Note that my build scripts (not shown) simply create (or recreate) a DEBUG directory using, in my case, meson, and build inside it (using, in my case, ninja).
Run, debug, attach, halt. These are another set of tasks, defined in "launch.json". Or at least they used to be. Microsoft has made such a hash of the documentation, I'm not even sure anymore.
Here is how I configured my VS for C++ using g++ compiler and it works great including debugging options:
tasks.json file
{
"version": "0.1.0",
"command": "g++",
"isShellCommand": true,
// compiles and links with debugger information
"args": ["-g", "-o", "hello.exe", "hello.cpp"],
// without debugger information
// "args": ["-o", "hello.exe", "hello.cpp"],
"showOutput": "always"
}
launch.json file
{
"version": "0.2.0",
"configurations": [
{
"name": "C++ Launch (Windows)",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceRoot}/hello.exe",
"MIMode": "gdb",
"miDebuggerPath": "C:\\MinGw\\bin\\gdb.exe",
"stopAtEntry": false,
"cwd": "${workspaceRoot}",
"externalConsole": false,
"visualizerFile": "${workspaceRoot}/my.natvis"
}
]
}
I also have 'C/C++ for Visual Studio Code' extension installed in VS Code
If your project has a CMake configuration it's pretty straight forward to setup VSCode, e.g. setup tasks.json like below:
{
"version": "0.1.0",
"command": "sh",
"isShellCommand": true,
"args": ["-c"],
"showOutput": "always",
"suppressTaskName": true,
"options": {
"cwd": "${workspaceRoot}/build"
},
"tasks": [
{
"taskName": "cmake",
"args": ["cmake ."]
},
{
"taskName": "make",
"args" : ["make"],
"isBuildCommand": true,
"problemMatcher": {
"owner": "cpp",
"fileLocation": "absolute",
"pattern": {
"regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
"file": 1,
"line": 2,
"column": 3,
"severity": 4,
"message": 5
}
}
}
]
}
This assumes that there is a folder build in the root of the workspace with a CMake configuration.
There's also a CMake integration extension that adds a "CMake build" command to VScode.
PS! The problemMatcher is setup for clang-builds. To use GCC I believe you need to change fileLocation to relative, but I haven't tested this.
With an updated VS Code you can do it in the following manner:
Hit (Ctrl+P) and type:
ext install cpptools
Open a folder (Ctrl+K & Ctrl+O) and create a new file inside the folder with the extension .cpp (ex: hello.cpp):
Type in your code and hit save.
Hit (Ctrl+Shift+P and type, Configure task runner and then select other at the bottom of the list.
Create a batch file in the same folder with the name build.bat and include the following code to the body of the file:
#echo off
call "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" x64
set compilerflags=/Od /Zi /EHsc
set linkerflags=/OUT:hello.exe
cl.exe %compilerflags% hello.cpp /link %linkerflags%
Edit the task.json file as follows and save it:
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "0.1.0",
"command": "build.bat",
"isShellCommand": true,
//"args": ["Hello World"],
"showOutput": "always"
}
Hit (Ctrl+Shift+B to run Build task. This will create the .obj and .exe files for the project.
For debugging the project, Hit F5 and select C++(Windows).
In launch.json file, edit the following line and save the file:
"program": "${workspaceRoot}/hello.exe",
Hit F5.
Can use Extension Code Runner to run code with play icon on top Right ans by shortcut key :Ctrl+Alt+N and to abort Ctrl+Alt+M. But by default it only shows output of program but for receiving input you need to follow some steps:
Ctrl+, and then settings menu opens and Extensions>Run Code Configuration scroll down its attributes and find Edit in settings.json click on it and add following code insite it :
{
"code-runner.runInTerminal": true
}
You can reference to this latest gist having a version 2.0.0 task for Visual Studio Code, https://gist.github.com/akanshgulati/56b4d469523ec0acd9f6f59918a9e454
You can easily compile and run each file without updating the task. It's generic and also opens the terminal for input entries.
There's now a C/C++ language extension from Microsoft. You can install it by going to the "quick open" thing (Ctrl+p) and typing:
ext install cpptools
You can read about it here:
https://blogs.msdn.microsoft.com/vcblog/2016/03/31/cc-extension-for-visual-studio-code/
It's very basic, as of May 2016.

External VS Code Compiler

is there any way to connect an external compiler to VS Code?
I have a compiler delivered by the client which is located in a folder:
app\cc\linuxacu\x86_64-poky-mingw32\usr\bin\poky-linux-gnu
I would like to add it to VS Code to be able to compile the project directly in the editor. Is it possible to create a 'task' that will use the compiler from the specified path?
Additionally, I need to compile two types of files:
Makefile located under this path:
app\Makefile.mk
The C file that is currently open
app\src\device\type\src
I tried to create a task but unfortunately I can't run it properly.
Result:
The terminal process failed to launch: Starting directory (cwd)
"C:/Users/Kxk/app/Makefile.mk" does not exist.
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "C/C++ LinuxARM Compiler Makefile",
"type": "shell",
"command": "C:/Users/Kxk/app/cc/linuxacu/x86_64-poky-mingw32/usr/bin/poky-linux-gnu/poky-linux-gnu-gcc",
"args": [
"-g"
],
"options": {
"cwd": "C:/Users/Kxk/app/Makefile.mk",
//"cwd": "${file}"
},
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": [
"$gcc"
]
}
]
}

tasks.json dependsOn not waiting for completion

I am setting up a build process which incorporates bash scripts already defined as a first-step into using tasks.json in my builds. Scripts must be run in order and it is essential that they run in sequence and not parallel since subsequent scripts depend on the output of the previous ones.
Setting "dependsOrder": "sequence" is ensuring the scripts are run in order, but there is an overlap such that the second script is being called before the first script is called and so on; ie: they are still running in parallel.
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"label": "pageBuilder",
"tasks": [
{
"label": "build",
"group": {
"kind": "build",
"isDefault": true
},
"dependsOrder": "sequence",
"dependsOn": [
"buildCorePages", "convertMarkdownToHtml", "buildArticles"
],
"problemMatcher": "$gcc"
},
{
"label": "convertMarkdownToHtml",
"type": "shell",
"command": "${workspaceRoot}\\build_scripts\\convertMarkdownToHtml.sh"
},
{
"label": "buildCorePages",
"type": "shell",
"command": "${workspaceRoot}\\build_scripts\\buildCorePages.sh"
},
{
"label": "buildArticles",
"type": "shell",
"command": "${workspaceRoot}\\build_scripts\\buildArticles.sh"
}
]
}
How can I force a wait for script completion?

Program 'main.exe' failed to run: The specified executable is not a valid application for this OS platform

“I’m setting up Visual Studio Code, and when I try to run my main.cpp (main.exe when executed), It is showing the error mentioned above.
From what I read about the issue online. I think it is because of wrong written in the c_cpp_properties.json file. But I can't figure out where to make the changes.
#Code:
#include <iostream>
int main()
{
std::cout<<"Hello World"<<std::endl;
}
#c_cpp_properties.json :
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"compilerPath": "C:\\MinGW\\bin\\gcc.exe",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "clang-x64",
"browse": {
"path": [
"${workspaceRoot}",
"C:\\MinGW\\lib\\gcc\\mingw32\\8.2.0\\include\\c++"
],
"limitSymbolsToIncludedHeaders": true,
"databaseFilename": ""
}
}
],
"version": 4
}
Error Message:
Program 'main.exe' failed to run: The specified executable is not a valid application for this OS platform.At line:1 char:1
+ .\main.exe+ ~~~~~~~~~~.
+ FullyQualifiedErrorId : NativeCommandFailed
You're getting this error because you're building on 64 bit windows machine with 32bit cpp.exe. So you're building for a different target machine.
To fix this, change your tasks.json file to point to g++.exe instead of cpp.exe.
To access your tasks.json file on windows (ctrl+shift+p) and then type "tasks"
change cpp.exe to g++.exe
I, too, faced the same error but rectified it with a simple solution
1.) First go and check your extensions whether you have installed the C/C++ by Microsoft.
2.) If not, do that first!
3.) If you have already installed, don't worry, check the version of your Visual Studio Code by clicking help in the menu bar and pressing About.
For version 2.0.0:
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "Build",
"type": "shell",
"command": "g++",
"args": [
"-o",
"main",
"-g",
"main.cpp"
],
"group": {
"kind": "build",
"isDefault": true
}
},
{
"label": "Run",
"type": "shell",
"command": ".\\main",
"problemMatcher": []
}
]
}
For version 1.0.0:
{
"version": "0.1.0",
"command": "make",
"isShellCommand": true,
"tasks": [
{
"taskName": "Makefile",
// Make this the default build command.
"isBuildCommand": true,
// Show the output window only if unrecognized errors occur.
"showOutput": "always",
// Pass 'all' as the build target
"args": ["all"],
// Use the standard less compilation problem matcher.
"problemMatcher": {
"owner": "cpp",
"fileLocation": ["relative", "${workspaceRoot}"],
"pattern": {
"regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
"file": 1,
"line": 2,
"column": 3,
"severity": 4,
"message": 5
}
}
}
]
}
4.) Check your version properly and paste the above-mentioned syntax in your tasks.json.
To go to tasks.json Do the following steps:
Press Ctrl+Shift+P.
You will see your command palette where you must type configure tasks. And select (“Tasks: Configure Task”).
You can type the above-mentioned syntax with respect to your Visual Studio Code Version.
Don't miss out the ending curly braces mentioned below the syntax
For me you just need to configure your task.json file
My tasks.json file is this:
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "Build",
"type": "shell",
"command": "g++",
"args": [
"-o",
"main",
"-g",
"main.cpp"
],
"group": {
"kind": "build",
"isDefault": true
}
},
{
"label": "Run",
"type": "shell",
"command": ".\\main",
"problemMatcher": []
}
]
}
Also to run the exe file the command is ".\filename" without the extension.
We can execute cpp Programs using
g++ name_of_file.cpp
./a
Or for c prgrams
gcc name_of_file.c
./a

Out/Input screen for Visual studio Code in C++ (on Linux)

I am using Visual Studio Code for the first time for programming C++ in a Linux (gnome) environment.
I have made a dummy .cpp file which asks me for an input value and then returns it in a string on the screen
However in Visual studio code I do not get an input or output screen.
I have tried in my tasks.json file to add "presentation" "reveal": "always"
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"taskName": "build hello world",
"type": "shell",
"command": "g++",
"args": [
"-g", "helloworld.cpp"
],
"group": {
"kind": "build",
"isDefault": true
},
"presentation": {
"reveal": "always"
}
}
]
}
I didn't really find any answers that could help me anywhere. There was a "terminal": "integrated" attribute, but this one is deprecated.