Configure VS Code for Microsoft C++
AI agents: See llms.txt for documentation discovery and navigation. Documentation articles are also available as Markdown by appending .md to the article URL. Join VS Code at Microsoft Ignite or catch the sessions online. A year of VS Code, wrapped. Explore the highlights. Configure VS Code for Microsoft C++ View as Markdown Ask in VS Code Ask in VS Code Insiders In this tutorial, you configure Visual Studio Code to use the Microsoft Visual C++ compiler and debugger on Windows.
After configuring VS Code, you will compile and debug a simple Hello World program in VS Code. This tutorial does not teach you details about the Microsoft C++ toolset or the C++ language. For those subjects, there are many good resources available on the Web. If you have any problems, feel free to file an issue for this tutorial in the VS Code documentation repository . Prerequisites To successfully complete this tutorial, you must do the following: Install Visual Studio Code .
Install the C/C++ extension for VS Code . You can install the C/C++ extension by searching for 'c++' in the Extensions view ( ⇧⌘X (Windows, Linux Ctrl+Shift+X ) ). Install the Microsoft Visual C++ (MSVC) compiler toolset. If you have a recent version of Visual Studio, open the Visual Studio Installer from the Windows Start menu and verify that the C++ workload is checked. Verify also that the MSVC build tools and a Windows SDK are selected.
If any of those components are not installed, check the appropriate boxes and select the Modify button in the installer. You can also install the Desktop development with C++ workload without a full Visual Studio IDE installation. From the Visual Studio Downloads page, scroll down until you see Tools for Visual Studio under the All Downloads section and select the download for Build Tools for Visual Studio 2026 . This will launch the Visual Studio Installer, which will bring up a dialog showing the available Visual Studio Build Tools workloads.
Check the Desktop development with C++ workload, ensure that the MSVC build tools and a Windows SDK are selected, then select Install . Note : You can use the C++ toolset from Visual Studio Build Tools along with Visual Studio Code to develop, build, and test any C++ code as long as you also have a valid Visual Studio license (either Community, Pro, or Enterprise). Check your Microsoft Visual C++ installation To use MSVC from a command line or VS Code, you must run from a Developer Command Prompt for Visual Studio .
An ordinary shell such as PowerShell, Bash, or the Windows command prompt does not have the necessary path environment variables set. To open the Developer Command Prompt for VS, start typing 'developer' in the Windows Start menu, and you should see it appear in the list of suggestions. The exact name depends on which version of Visual Studio or the Visual Studio Build Tools you have installed. Select the item to open the prompt.
You can test that you have the C++ compiler, cl.exe , installed correctly by typing 'cl' and you should see a copyright message with the version and basic usage description. If the Developer Command Prompt is using the BuildTools location as the starting directory (you wouldn't want to put projects there), navigate to your user folder ( C:\users\{your username}\ ) before you start creating new projects. Note : If for some reason you can't run VS Code from a Developer Command Prompt , you can find a workaround for building C++ projects with VS Code in Run VS Code outside a Developer Command Prompt .
Create Hello World From the Developer Command Prompt, create an empty folder called "projects" where you can store all your VS Code projects, then create a subfolder called "helloworld", navigate into it, and open VS Code ( code ) in that folder ( . ) by entering the following commands: mkdir projects cd projects mkdir helloworld cd helloworld code . The "code ." command opens VS Code in the current working folder, which becomes your "workspace".
As you go through the tutorial, you will see three files created in a .vscode folder in the workspace: tasks.json (build instructions) launch.json (debugger settings) c_cpp_properties.json (compiler path and IntelliSense settings) Add a source code file In the File Explorer title bar, select the New File button and name the file helloworld.cpp . Add hello world source code Now paste in this source code: #include <iostream> #include <vector> #include <string> using namespace std ; int main () { vector<string> msg { "Hello" , "C++" , "World" , "from" , "VS Code" , "and the C++ extension!" }; for ( const string& word : msg) { cout << word << " " ; } cout << endl; } Now press ⌘S (Windows, Linux Ctrl+S ) to save the file.
Notice how the file you just added appears in the File Explorer view ( ⇧⌘E (Windows, Linux Ctrl+Shift+E ) ) in the side bar of VS Code: You can also enable Auto Save to automatically save your file changes, by checking Auto Save in the main File menu. The Activity Bar on the far left lets you open different views such as Search , Source Control , and Run . You'll look at the Run view later in this tutorial. You can find out more about the other views in the VS Code User Interface documentation .
Note : When you save or open a C++ file, you may see a notification from the C/C++ extension about the availability of an Insiders version, which lets you test new features and fixes. You can ignore this notification by selecting the X ( Clear Notification ). Explore IntelliSense In your new 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: You can press the Tab key to insert the selected member; then, when you add the opening parenthesis, you will see information about any arguments that the function requires. Run helloworld.cpp Remember, the C++ extension uses the C++ compiler you have installed on your machine to build your program.
Make sure you have a C++ compiler installed before attempting to run and debug helloworld.cpp in VS Code. Open helloworld.cpp so that it is the active file. Press the play button in the top right corner of the editor. Choose C/C++: cl.exe build and debug active file from the list of detected compilers on your system. You'll only be asked to choose a compiler the first time you run helloworld.cpp . This compiler will be set as the "default" compiler in tasks.json file.
After the build succeeds, your program's output will appear in the integrated Terminal . If you get an error trying to build and debug with cl.exe, make sure you have started VS Code from the Developer Command Prompt for Visual Studio using the code . shortcut. The first time you run your program, the C++ extension creates tasks.json , which you'll find in your project's .vscode folder. tasks.json stores build configurations.
Your new tasks.json file should look similar to the JSON below: { "version" : "2.0.0" , "tasks" : [ { "type" : "shell" , "label" : "C/C++: cl.exe build active file" , "command" : "cl.exe" , "args" : [ "/Zi" , "/EHsc" , "/Fe:" , "${fileDirname} \\ ${fileBasenameNoExtension}.exe" , "${file}" ], "problemMatcher" : [ "$msCompile" ], "group" : { "kind" : "build" , "isDefault" : true }, "detail" : "Task generated by Debugger." } ] } Note : You can learn more about tasks.json variables in the variables reference .
The command setting specifies the program to run; in this case that is "cl.exe". The args array specifies the command-line arguments that will be passed to cl.exe. These arguments must be specified in the order expected by the compiler. This task tells the C++ compiler to take the active file ( ${file} ), compile it, and create an executable file ( /Fe: switch) in the current directory ( ${fileDirname} ) with the same name as the active file but
The rest of this page is on the live site.