Factsheet
What exactly is Visual Studio Code? - Stack Overflow
VS Code is a special type of text editor that is called a compiler?
compiler for visual studio code
How do I compile and run?
Visual Studio Code is just an editor, which features their intellisense thingy and some git and debugger integration.
EDIT: more info here: https://code.visualstudio.com/Docs
It is more of a simple code editor than an IDE and it's primary focus is editing web code (Html, Javascript, CSS), TypeScript, and C#. It provides advanced 'IDE like' features for these languages, but more basic features for other languages (syntax highlighting).
Also, see What is the Visual Studio Code editor built on
Quote from here: https://cs50.harvard.edu/python/2022/notes/0/
I just started the online Python course, and the very first sentence of the CS50P notes says, βVS Code is a special type of text editor that is called a compiler.β Iβm obviously new to programmingβhence why Iβm taking the courseβbut that doesnβt seem correct at all.
UPDATE: It has been corrected.
i'm new to coding, i'm on windows 11 and i would like to use visual studio code for c++ but i cant download a working compiler.
i've watched many videos online and none of them work.
to be more specific, i tried the first thing it says to download on sourceforge and it doesnt work.
then i scrolled down and downloaded MinGW-W64-install.exe and it says i downloaded it the wrong way, so i tried the other links below which do give me the build folder, but when i copy it and paste it on path it just doesn't do anything.
can anyone help me?
Iβve been programming for years now, in multiple languages. Iβve never used an IDE or anything like vs code. I usually just use a text editor and a terminal to do all my coding.
This whole process is starting to get annoying so I downloaded vs code but I cannot get anything to work. I donβt know what I am doing. According to the tutorials, I should be able to press the debug and run button and vs code will compile and run my code, but I canβt get this to work. Itβs saying I need a configuration, or that blah blah blah.
So far, Iβve only been able to get python to work. So my questions are: what is a configuration? Why do I need one? How do I get c++ to work with the push of one button?
You need to also install a c++ compiler for vscode to compiler your code, along with the c++ compiler.
Mingw-x64 is one framework which will allow you to compile c/c++ code
CPP instructions on VSCode site
MinGW instructions on VSCode site
The C/C++ Extension Pack in Visual Studio Code does not provide a compiler. It just gives you editing support i.e. IntelliSense, Debugging, Syntax Highlighting, etc.
To compile C++, you should install a compiler and then configure VS Code.
For macOS,
xcode-select --install, installs clangOn Windows, You gotta install MinGW-w64 or use MSYS2 (I'm mostly a linux user but even then I recommend MSYS2 since its a bit less of a hassle)
On Linux, you can use g++ (This is just gcc for C++)
After installing a compiler, try manually compiling the code from the terminal. If this works, you are good to go; else, you need to add the compiler to the PATH. Now let's set it up with VS Code.
Press
Ctrl/Cmd + Shift + Ptype inTasks: Configure Default Build TaskIn this menu, you shall see your list of installed compilers. If you do not, something ain't right with your installation of the C/C++ Extension in VS Code. Restarting / Reinstalling Extension(s) may fix this right up.
Once you see the list, select your compiler, this should create a
tasks.jsonfile.
And viola! C++ compiling should now work as expected.
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
}
}
}
]
}