Home >Computer Tutorials >Computer Knowledge >How to configure VS Code for Microsoft C++
I chose C as my first language when I embarked on my programming journey. C/C++ is often regarded as the starting point of the programming world. In this article, we'll look at how to configure VS Code for Microsoft C as this can present some challenges since C requires a compiler and interpreter to run your code correctly.
To configure VS Code for Microsoft C++, follow the steps mentioned below.
Let’s talk about it in detail.
First, visit code.VisualStudio.com to download the VS Code application for your operating system. After installation, make sure Add to Path is checked in the options (requires shell restart).
Now that we have Visual Studio Code installed on our computer, it's time to get the correct extension, which will tell Visual Studio Code, "Hey, this is a C code!".
To perform the same steps, first open VS Code, select the Extensions icon in the top menu or press Ctrl Shift X. Then, enter "C/C" in the search bar, and the system will automatically search for related extensions. Just click on the C/C extension and then click "Install".
After installing the C/C extension, you need to install the Code Runner extension. This tool makes it easy for us to run code snippets or files. But note that we also need to install the compiler next.
Our computer systems are built using electronic switches and cables that can only work with the binary numbers 1 and 0. In order for your computer's central processing unit (CPU) to understand your high-level C code, you need a compiler that can translate it into machine language. For this reason, we will install and configure the MinGW compiler.
First, let’s download the MinGW compiler from Sourceforge.net. You can get the compiler for free. After installing the MinGW installer, go to the download folder, run the installer and follow the steps mentioned below.
Once the MinGW package is installed, you cannot start coding immediately, we need to set and configure environment variables.
Next, we need to set the path and configure environment variables. To perform the same operation, first open File Explorer and then go to the local disk C>Mingw&>Bin. Then copy the location, it should look like C:\MinGWbin. Make sure to paste it somewhere accessible.
To configure environment variables, search for and open "View advanced system settings". In the Advanced tab, click Environment Variables. Then you have to click on the path from the Environment Variables section and then click on Edit. Then click New, enter the path we asked you to copy earlier, and finally click OK. Finally, click OK and close the System Properties window.
In this way, we configure environment variables for our compiler. To confirm, open a command prompt as an administrator and run the following command.
G++--版本
If you receive the following message or a similar one, you are ready to get to work.
G (MinGW.org GCC-6.3.0-1)6.3.0Copyright (C) 2016 Free Software Foundation, Inc.
Finally, you can start coding.
Read: Enhance your code on Visual Studio Code with extensions
To run C in Microsoft Visual Code, you need to install the C extension and other basic extensions, then download and configure the compiler, you can use Clang or MinGW compiler. We have previously detailed how to install C and configure the compiler.
Read: The Best C Extensions for Visual Studio Code
To set default code in VS Code, first press Ctrl Shift P to open the command palette, then search for "> Configure User Fragments" and click on it. Next, search for "cpp.json" and open the file. Finally, replace the comments in the file with the snippet code that has been copied to the clipboard.
Also Read: Best Free C IDE for Windows.
The above is the detailed content of How to configure VS Code for Microsoft C++. For more information, please follow other related articles on the PHP Chinese website!