C/C++ support for Visual Studio Code is provided by a Microsoft C/C++ extension to enable cross-platform C and C++ development on Windows, Linux, and macOS.
Install the extension
- Open VS Code.
- Select the Extensions view icon on the Activity bar or use the keyboard shortcut (⇧⌘X (Windows, Linux Ctrl+Shift+X)).
- Search for
'C++'
. - Select Install.
After you install the extension, when you open or create a *.cpp
file, you will have syntax highlighting (colorization), smart completions and hovers (IntelliSense), and error checking.
Install a compiler
C++ is a compiled language meaning your program's source code must be translated (compiled) before it can be run on your computer. VS Code is first and foremost an editor, and relies on command-line tools to do much of the development workflow. The C/C++ extension does not include a C++ compiler or debugger. You will need to install these tools or use those already installed on your computer.
There may already be a C++ compiler and debugger provided by your academic or work development environment. Check with your instructors or colleagues for guidance on installing the recommended C++ toolset (compiler, debugger, project system, linter).
Some platforms, such as Linux or macOS, have a C++ compiler already installed. Most Linux distributions have the GNU Compiler Collection (GCC) installed and macOS users can get the Clang tools with Xcode.
Check if you have a compiler installed
Make sure your compiler executable is in your platform path (%PATH
on Windows, $PATH
on Linux and macOS) so that the C/C++ extension can find it. You can check availability of your C++ tools by opening the Integrated Terminal (⌃` (Windows, Linux Ctrl+`)) in VS Code and trying to directly run the compiler.
Checking for the GCC compiler g++
:
g++ --version
Checking for the Clang compiler clang
:
clang --version
Note: If you would prefer a full Integrated Development Environment (IDE), with built-in compilation, debugging, and project templates (File > New Project), there are many options available, such as the Visual Studio Community edition.
If you don't have a compiler installed, in the example below, we describe how to install the Minimalist GNU for Windows (MinGW) C++ tools (compiler and debugger). MinGW is a popular, free toolset for Windows. If you are running VS Code on another platform, you can read the C++ tutorials, which cover C++ configurations for Linux and macOS.
Example: Install MinGW-x64
We will install Mingw-w64 via MSYS2, which provides up-to-date native builds of GCC, Mingw-w64, and other helpful C++ tools and libraries. You can download the latest installer from the MSYS2 page or use this link to the installer.
Follow the Installation instructions on the MSYS2 website to install Mingw-w64. Take care to run each required Start menu and pacman
command.
You will need to install the full Mingw-w64 toolchain (pacman -S --needed base-devel mingw-w64-x86_64-toolchain
) to get the gdb
debugger.
Add the MinGW compiler to your path
Add the path to your Mingw-w64 bin
folder to the Windows PATH
environment variable by using the following steps:
- In the Windows search bar, type 'settings' to open your Windows Settings.
- Search for Edit environment variables for your account.
- Choose the
Path
variable in your User variables and then select Edit. - Select New and add the Mingw-w64 destination folder path, with
\mingw64\bin
appended, to the system path. The exact path depends on which version of Mingw-w64 you have installed and where you installed it. If you used the settings above to install Mingw-w64, then add this to the path:C:\msys64\mingw64\bin
. - Select OK to save the updated PATH. You will need to reopen any console windows for the new PATH location to be available.
Check your MinGW installation
To check that your Mingw-w64 tools are correctly installed and available, open a new Command Prompt and type:
gcc --versiong++ --versiongdb --version
If you don't see the expected output or g++
or gdb
is not a recognized command, make sure your PATH entry matches the Mingw-w64 binary location where the compiler tools are located.
If the compilers do not exist at that PATH entry, make sure you followed the instructions on the MSYS2 website to install Mingw-w64.
Hello World
To make sure the compiler is installed and configured correctly, we'll create the simplest Hello World C++ program.
Create a folder called "HelloWorld" and open VS Code in that folder (code .
opens VS Code in the current folder):
mkdir HelloWorldcd HelloWorldcode .
The "code ." command opens VS Code in the current working folder, which becomes your "workspace". Accept the Workspace Trust dialog by selecting Yes, I trust the authors since this is a folder you created.
Now create a new file called helloworld.cpp
with the New File button in the File Explorer or File > New File command.
Add Hello World source code
Now paste in this source code:
#include <iostream>int main(){ std::cout << "Hello World" << std::endl;}
Now press ⌘S (Windows, Linux Ctrl+S) to save the file. You can also enable Auto Save to automatically save your file changes, by checking Auto Save in the main File menu.
Build Hello World
Now that we have a simple C++ program, let's build it. Select the Terminal > Run Build Task command (⇧⌘B (Windows, Linux Ctrl+Shift+B)) from the main menu.
This will display a dropdown with various compiler task options. If you are using a GCC toolset like MinGW, you would choose C/C++: g++.exe build active file.
This will compile helloworld.cpp
and create an executable file called helloworld.exe
, which will appear in the File Explorer.
Run Hello World
From a command prompt or a new VS Code Integrated Terminal, you can now run your program by typing ".\helloworld".
If everything is set up correctly, you should see the output "Hello World".
This has been a very simple example to help you get started with C++ development in VS Code. The next step is to try one of the tutorials listed below on your platform (Windows, Linux, or macOS) with your preferred toolset (GCC, Clang, Microsoft C++) and learn more about the Microsoft C/C++ extension's language features such as IntelliSense, code navigation, build configuration, and debugging.
Tutorials
Get started with C++ and VS Code with tutorials for your environment:
- GCC on Windows via MinGW
- Microsoft C++ on Windows
- GCC on Linux
- GCC on Windows Subsystem For Linux
- Clang/LLVM on macOS
- CMake Tools on Linux
Documentation
You can find more documentation on using the Microsoft C/C++ extension under the C++ section of the VS Code website, where you'll find topics on:
- Debugging
- Editing
- Settings
- FAQ
Remote Development
VS Code and the C++ extension support Remote Development allowing you to work over SSH on a remote machine or VM, inside a Docker container, or in the Windows Subsystem for Linux (WSL).
To install support for Remote Development:
- Install the VS Code Remote Development Extension Pack.
- If the remote source files are hosted in WSL, use the WSL extension.
- If you are connecting to a remote machine with SSH, use the Remote - SSH extension.
- If the remote source files are hosted in a container (for example, Docker), use the Dev Containers extension.
Enhance completions with AI
GitHub Copilot is an AI-powered code completion tool that helps you write code faster and smarter. You can use the GitHub Copilot extension in VS Code to generate code, or to learn from the code it generates.
GitHub Copilot provides suggestions for numerous languages and a wide variety of frameworks, and it works especially well for Python, JavaScript, TypeScript, Ruby, Go, C# and C++.
You can learn more about how to get started with Copilot in the Copilot documentation.
Feedback
If you run into any issues or have suggestions for the Microsoft C/C++ extension, please file issues and suggestions on GitHub.
1/21/2022
FAQs
C++ programming with Visual Studio Code? ›
It is a software editor that has a rich extension of various languages like C++, C+, C, Java, Python, PHP, Go, etc. and runtime language extensions such as .NET and Unity. It is easy to edit, build, syntax highlighting, snippets, code refactoring and debugging.
Is VS Code good for C C++? ›It is a software editor that has a rich extension of various languages like C++, C+, C, Java, Python, PHP, Go, etc. and runtime language extensions such as .NET and Unity. It is easy to edit, build, syntax highlighting, snippets, code refactoring and debugging.
Is Visual Studio C++ good? ›Many developers consider Visual Studio the ultimate IDE for C++ code development. Visual Studio 2019 version 16.1 added support for using C++ with the Windows Subsystem for Linux (WSL), which lets you run a lightweight Linux environment directly on Windows.
What is the difference between Visual Studio and Visual Studio Code for C++? ›“Visual Studio” and “Visual Studio Code” are not the same thing. Visual Studio is an integrated development environment (IDE) and Visual Studio Code is a rich text editor like Sublime Text and Atom.
Can I learn C++ in Visual Studio? ›C++ C++, C, and assembly language development tools and libraries are available as part of Visual Studio on Windows.
Is VS Code enough? ›A developer can rely on Visual Studio Code for all kinds of development, as long as they pair it with the right tools. VS Code comes with built-in support for JavaScript, Node. js, and TypeScript.
Is it better to code in C or Python? ›C is a general-purpose, procedural programming language. Python is an interpreted, high-level, general-purpose programming language. When compared to interpreted programs, compiled programs run faster therefore C is faster.
Is it difficult to learn Visual C++? ›C++ is known to be one of the most difficult programming languages to learn over other popular languages like Python and Java.
Which language is Visual Studio best for? ›JavaScript is a first-class language in Visual Studio. You can use most or all of the standard editing aids (code snippets, IntelliSense, and so on) when you write JavaScript code in the Visual Studio IDE.
Which is better Visual Studio or Dev C++? ›Visual C++ is from Microsoft. It supports plain C++ in addition to windows libraries [MFC, COM, Win32]. If you want to develop applications for windows and want to do it faster use Visual Studio. Applications can also be developed with Dev C++, but its a lot of work configuring the libraries and so on.
Is Visual Studio Code better than Python? ›
Although Python has many IDEs and code editors, PyCharm and VS Code have remained favorites among developers over time. Both PyCharm and VS Code are excellent Python code editors. However, while PyCharm is an IDE, VS Code is a code editor that, through extensions, offers a similar experience to an IDE.
What is better than VS Code? ›Atom, Visual Studio, Eclipse, IntelliJ IDEA, and WebStorm are the most popular alternatives and competitors to Visual Studio Code.
What version of C++ is in Visual Studio? ›Visual C++ 2022 (also known as Visual C++ 14.30) was released on November 8, 2021.
Can I get a job if I learn C++? ›C++ has an immense job market extending over various industries like Finance, Application Development, Game Development, Virtual Reality, etc. The most popular use of C++ is for developing extensive software infrastructure and applications running on limited resources.
Is learning C++ enough to get a job? ›C++ allows you to work on a wide array of projects. Ultimately, C++ is enough to get a job as a programmer, as long as you can invest your time in enhancing your programming skills. You must also make sure that you learn Data structures and Algorithms.
What compiler should I use for C++ Visual Studio Code? ›Microsoft C++ Compiler (MSVC)
This is the default compiler for most Visual Studio C++ projects and is recommended if you are targeting Windows. Compiler options for the Microsoft C++ compiler.
Cons: one potential drawback could be its relatively high system requirements compared to some other lightweight text editors. Running Visual Studio Code on low-spec hardware or older machines may result in slower performance or lagging, especially when working with large files or complex projects.
What are the disadvantages of VS Code? ›It is difficult to think of cons for VSCode as I truly enjoy it in its entirety. One downside of being extension/plugin based is that you are subject to an extension or plugin being poorly written or containing security vulnerabilities. Additionally, I have had buggy issues with IntelliSense not working.
What are the disadvantages of Visual Studio? ›"The only con to Visual studio is its User interface as it becomes very boring to code on an interface which has no plugins and drag and drops options."
Which is harder C or C++? ›3: Is C easier than C++? Ans. C is easier to learn because of its hands-on characteristics. But C++ is easier to code with its fixed structures and principles.
Should I learn C++ as a beginner? ›
Both Python and C++ are popular, beginner-friendly programming languages. For some, choosing which of these general-purpose languages to learn first is a matter of personal preference. For others, one may be more beneficial to learn for a specific project.
Why is C so much harder than Python? ›The syntax of a C program is harder than Python. Python uses an automatic garbage collector for memory management. In C, the Programmer has to do memory management on their own. Python is a General-Purpose programming language.
How many hours will take to learn C++? ›You can expect to master the syntax of C++ in about two to three months if you devote about 10 hours every week to learning C++. However, to become highly proficient at programming in C++, expect to spend at least one year studying full-time.
How many days will it take to learn C++? ›C++ is somewhat difficult to learn, especially if you have never programmed before or you have never used a low-level programming language before. If you are a beginner with no programming experience, you should expect it to take at least three months to learn the basics.
How long does it take to learn C++ to get a job? ›So, if you wonder how long does it take to learn c++, you can probably become a very efficient programmer within 6 months, but mastery of C++ can take at least 2 to 3 years.
Why is Visual Studio Code so good? ›Robust and extensible architecture
Architecturally, Visual Studio Code combines the best of web, native, and language-specific technologies. Using Electron, VS Code combines web technologies such as JavaScript and Node. js with the speed and flexibility of native apps.
Java and Python are the two most commonly used programming languages in Amazon Web Services (AWS). If you're at the beginning of your journey as a cloud professional, you may be wondering what coding experience you'll need to break into the ecosystem.
Is Visual Studio a high level language? ›Visual Basic is a high level programming language which evolved from the earlier DOS version called BASIC. BASIC means “Beginners All-purpose Symbolic Instruction Code”. Visual Basic is an example of a graphical-based language. A graphical-based language allows the user to work directly with graphics.
Which IDE should I use for C++? ›What Is The Best C++ IDE? Although it is difficult to choose the right IDE, some of the most popular IDEs include Visual Studio, Code::Blocks, CLion and Eclipse CDT. Most developers use multiple IDEs, so doing your research to find the benefits of each one helps you find the best C++ IDE for you.
What is the difference between C++ and Visual C++? ›Key Differences Between C++ and Visual C++
C++ is an object-oriented programming language, whereas Visual C++ is the Integrated Development Environment (IDE) and compiler for C and C++ language.
Which Visual Studio should I download for C++? ›
For core C and C++ support, choose the "Desktop development with C++" workload. It comes with the default core editor, which includes basic code editing support for over 20 languages, the ability to open and edit code from any folder without requiring a project, and integrated source code control.
Is VS Code beginner friendly? ›While marketing primarily to professional programmers, VS Code is an excellent editor for students and other learner just getting started with HTML and CSS.
Is Visual Studio the best IDE? ›Visual Studio is the best IDE to build rich, beautiful, cross platform applications for Windows, Mac, Linux, iOS, and Android.
Which is better Anaconda or Visual Studio Code? ›Anaconda is an open source Python distribution / data discovery & analytics platform. Visual Studio (now in the 2022 edition) is a 64-bit IDE that makes it easier to work with bigger projects and complex workloads, boasting a fluid and responsive experience for users.
Is VS Code used in industry? ›We have data on 18,229 companies that use Visual Studio Code. The companies using Visual Studio Code are most often found in United States and in the Information Technology and Services industry. Visual Studio Code is most often used by companies with 50-200 employees and 1M-10M dollars in revenue.
Is VS Code a heavy software? ›VS Code is lightweight and should easily run on today's hardware. We recommend: 1.6 GHz or faster processor.
Is Visual C++ still being used? ›C++ is still being used to develop Desktop based applications, Games and Gaming Engines, 2D and 3D animations, Developing Web Browsers, Database Software, Media Access Software, Compilers, Operating Systems, Printing and Scanning Applications, Engineering and Medical Applications, Embedded and Real-time Applications.
Does Visual Studio have its own C++ compiler? ›Visual Studio C/C++ IDE and Compiler for Windows.
What build system does Visual Studio use for C++? ›The MSVC toolset
The Microsoft C++ compiler, linker, standard libraries, and related utilities make up the MSVC compiler toolset (also called a toolchain or "build tools"). These are included in Visual Studio.
Average ₹25,643 per month.
Do companies hire C++ developers? ›
You can hire C++ developers to create utilities and libraries for smooth interaction between applications and operating systems on multiple system layers.
How much money can a programmer make in C++? ›C++ developer salaries typically range between $75,000 and $149,000 a year. The average hourly rate for c++ developers is $50.98 per hour. Location, education, and experience impacts how much a c++ developer can expect to make.
How long does it take to be a good C++ programmer? ›However, if you're starting from scratch with this language, you will probably spend over 6 months to learn it at the most basic level. To learn C++ at a high enough level to get a C++ programming job would most likely take you 3-4 years.
Are C++ coders in demand? ›Yes, C++ is still a popular and in-demand programming language in 2023, and a career in C++ programming can be rewarding. Even though the emergence of newer languages has impacted the IT sector, C++ remains the language of choice for many industries.
Is there a shortage of C++ programmers? ›There is no shortage of companies that hire C/C++ programmers.
What's the difference between Visual Studio and Visual Studio Code? ›Visual Studio is an Integrated Development Environment, also known as an IDE. Visual Studio Code is a code editor. A developer can easily edit their code. VS is slower when it comes to performing across different platforms.
Is Visual Studio Code a good IDE for C++? ›VS Code Pros and Cons
VS Code is a user-friendly IDE with millions of community members actively using it. However, for C++ beginners, it only goes as far as providing IntelliSense. You have to plug in new features using extensions that eventually catch up with you as that lightweight factor goes through the window.
Simply open VS Code/VS Code Insiders, open any folder, and create any file with the extension .c for the C file and .cpp for the C++ file. After writing your code, you can run the code directly using the play button you'll find in the upper right corner.
Is VS Code good enough for C#? ›The C# Player's Guide primarily focuses on Visual Studio Community Edition, but if you are on Linux or Mac, or just want a lightweight editor, Visual Studio Code is a great choice. Visual Studio Code is more editor and less Integrated Development Environment (IDE).
Which language is best for VS Code? ›JavaScript is a first-class language in Visual Studio. You can use most or all of the standard editing aids (code snippets, IntelliSense, and so on) when you write JavaScript code in the Visual Studio IDE.
Is VS Code good for C#? ›
The C# support in Visual Studio Code is optimized for cross-platform . NET development (see working with . NET and VS Code for another relevant article). Our focus with VS Code is to be a great editor for cross-platform C# development.
Can you code anything with C? ›C is a versatile language that can create all sorts of applications. It's used to write the operating system for many of the world's most popular computers and the software that runs on them. It's also used to create the websites and apps we use daily.
How to setup C in Visual Studio Code? ›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 (Ctrl+Shift+X). Get the latest version of Mingw-w64 via MSYS2, which provides up-to-date native builds of GCC, Mingw-w64, and other helpful C++ tools and libraries.
What is C++ used for? ›C++ (or “C-plus-plus”) is a general-purpose programming and coding language. C++ is used in developing browsers, operating systems, and applications, as well as in-game programming, software engineering, data structures, etc.
How much more difficult is C++ than C#? ›C# is much easier to learn than C++. C# is a simpler, high-level-of-abstraction language, while C++ is a low-level language with a higher learning curve.
Why is VS Code so popular? ›Robust and extensible architecture
Architecturally, Visual Studio Code combines the best of web, native, and language-specific technologies. Using Electron, VS Code combines web technologies such as JavaScript and Node. js with the speed and flexibility of native apps.
Although Python has many IDEs and code editors, PyCharm and VS Code have remained favorites among developers over time. Both PyCharm and VS Code are excellent Python code editors. However, while PyCharm is an IDE, VS Code is a code editor that, through extensions, offers a similar experience to an IDE.
Is VS Code enough for Unity? ›Visual Studio Code can be a great companion to Unity for editing C# files. All of the C# features are supported and more. In the screen below, you can see code colorization, bracket matching, IntelliSense, CodeLens and that's just the start.
Is VS Code enough for Python? ›VS Code comes with great debugging support for Python, allowing you to set breakpoints, inspect variables, and use the debug console for an in-depth look at how your program is executing step by step. Debug a number of different types of Python applications, including multi-threaded, web, and remote applications.
Is VS Code good for machine learning? ›The Azure Machine Learning extension for VS Code provides a user interface to: Manage Azure Machine Learning resources (experiments, virtual machines, models, deployments, etc.) Develop locally using remote compute instances. Train machine learning models.