projects
where you can store all your VS Code projects, then create a subfolder called helloworld
, navigate into it, and open VS Code in that folder by entering the following commands:code .
command opens VS Code in the current working folder, which becomes your 'workspace'. As you go through the tutorial, you will create three files in a .vscode
folder in the workspace:tasks.json
(compiler build settings)launch.json
(debugger settings)c_cpp_properties.json
(compiler path and IntelliSense settings)helloworld.cpp
.X
(Clear Notification).helloworld.cpp
file, hover over vector
or string
to see type information. After the declaration of the msg
variable, start typing msg.
as you would when calling a member function. You should immediately see a completion list that shows all the member functions, and a window that shows the type information for the msg
object:tasks.json
file to tell VS Code how to build (compile) the program. This task will invoke the Clang C++ compiler to create an executable file from the source code.helloworld.cpp
open in the editor because the next step uses the active file in the editor as context to create the build task in the next step.tasks.json
file in the .vscode
folder and open it in the editor.'args'
is updated to compile with C++17 because our helloworld.cpp
uses C++17 language features.'cwd'
) to the folder where helloworld.cpp
is.command
setting specifies the program to run. In this case, 'clang++'
is the driver that causes the Clang compiler to expect C++ code and link against the C++ standard library.args
array specifies the command-line arguments that will be passed to clang++. These arguments must be specified in the order expected by the compiler.${file}
), and create an output file (-o
switch) in the current directory (${fileDirname}
) with the same name as the active file (${fileBasenameNoExtension}
), resulting in helloworld
for our example.label
value is what you will see in the tasks list. Name this whatever you like.problemMatcher
value selects the output parser to use for finding errors and warnings in the compiler output. For clang++, you'll get the best results if you use the $gcc
problem matcher.'isDefault': true
value in the group
object specifies that this task will be run when you press ⇧⌘B (Windows, Linux Ctrl+Shift+B). This property is for convenience only; if you set it to false
, you can still build from the Terminal menu with Terminal > Run Build Task. Excel to pdf converter app.tasks.json
variables in the variables reference.helloworld.cpp
. Because we want to build helloworld.cpp
it is important that this file be the one that is active in the editor for the next step.helloworld
folder as the working directory. Run ls
and you should now see the executable helloworld
along with the debugging file (helloworld.dSYM
).helloworld
in the terminal by typing ./helloworld
.tasks.json
to build multiple C++ files by using an argument like '${workspaceFolder}/*.cpp'
instead of ${file}
. This will build all .cpp
files in your current folder. You can also modify the output filename by replacing '${fileDirname}/${fileBasenameNoExtension}'
with a hard-coded filename (for example '${workspaceFolder}/myProgram.out'
).launch.json
file to configure VS Code to launch the LLDB debugger when you press F5 to debug the program.launch.json
file, opens it in the editor, and builds and runs 'helloworld'. Your launch.json
file will look something like this:program
setting specifies the program you want to debug. Here it is set to the active file folder ${fileDirname}
and active filename ${fileBasenameNoExtension}
, which if helloworld.cpp
is the active file will be helloworld
.stopAtEntry
value is set to false
.stopAtEntry
value to true
to cause the debugger to stop on the main
method when you start debugging.preLaunchTask
value matches the label
of the build task in the tasks.json
file.helloworld.cpp
so that it is the active file in the editor. This is important because VS Code uses the active file to determine what you want to debug.main
method. This is a breakpoint that the C++ extension automatically sets for you:for (const string& word : msg)
statement is highlighted.vector
and string
classes that are invoked when the msg
variable is created and initialized. Notice the change in the Variables window. The contents of msg
are visible because that statement has completed.cout
statement. Note As of the March 2019 version of the extension, no output will appear in the DEBUG CONSOLE until the last cout
completes.word
, which is the name of the loop variable. Now view the Watch window as you step through the loop.c_cpp_properties.json
file, which allows you to change settings such as the path to the compiler, include paths, which C++ standard to compile against (such as C++17), and more..vscode/c_cpp_properties.json
. If you open that file directly, it should look something like this:compilerPath
is an important configuration setting. The extension uses it to infer the path to the C++ standard library header files. When the extension knows where to find those files, it can provide useful features like smart completions and Go to Definition navigation.compilerPath
with the default compiler location based on what it finds on your system. The compilerPath
search order is:/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks
.vscode
folder in a new project folder (workspace) and change the names of the source file(s) and executable as needed.undefined _main
, or attempting to link with file built for unknown-unsupported file format
, and so on) occurs when helloworld.cpp
is not the active file when you start a build or start debugging. This is because the compiler is trying to compile something that isn't source code, like your launch.json
, tasks.json
, or c_cpp_properties.json
file.tasks.json
build task to use the clang++ argument --std=c++17
. By default, clang++ uses the C++98 standard, which doesn't support the initialization used in helloworld.cpp
. Make sure to replace the entire contents of your tasks.json
file with the code block provided in the Build helloworld.cpp section.'externalConsole': true
. A terminal window opens, but it does not actually allow you type any input.tasks.json
:PS: This was published on my Blog here.
A compiler is a special program that processes statements written in a particular programming language like C++ and turns them into machine language or 'code' that a computer's processor uses.
MinGW, a contraction of 'Minimalist GNU for Windows', is a minimalist development environment for native Microsoft Windows applications.
mingw32-gcc-g++
then select “Mark for Installation”C:MinGWbin
. Now you have to include this directory in your environment variable PATH. If you've been using computers for a while now you should know how to do this already, but if you don't, here are a few resources:C, C++, Java, JavaScript, PHP, Python, Perl, Perl 6, Ruby, Go, Lua, Groovy, PowerShell, BAT/CMD, BASH/SH, F# Script, F# (.NET Core), C# Script, C# (.NET Core), VBScript, TypeScript, CoffeeScript, Scala, Swift, Julia, Crystal, OCaml Script, R, AppleScript, Elixir, Visual Basic .NET, Clojure, Haxe, Objective-C, Rust, Racket, AutoHotkey, AutoIt, Kotlin, Dart, Free Pascal, Haskell, Nim, D, Lisp, Kit, and custom command.
test.cpp
Ctrl+Alt+N
Ctrl+Alt+M
Cannot edit in read-only terminal
.Run in Terminal
(Whether to run code in Integrated Terminal) Check the box.setting.json
file, add: