🔔 Get the scoop first! 📢 Join our Telegram for instant updates! 🚀. Join Channel Join Group!

How to Get Started with C/C++ in Visual Studio Code

Learn how to set up Visual Studio Code for C and C++ programming in this step-by-step guide. Includes instructions on installing the necessary extensi
Please wait 0 seconds...
Scroll Down and click on Go to Link for destination
Congrats! Link is Generated
Visual Studio Code Setup Instruction

Here's a step-by-step tutorial to set up Visual Studio Code for C and C++ programming on Windows and Mac.

On Windows (Manual):

Download and install Visual Studio Code: You can download the latest version of Visual Studio Code from the official website (https://code.visualstudio.com/download). Install the software following the instructions on the screen.

Download VS Code

I personally prefer going for a 64-bit installation. After, downloading VS Code Simply install it to your system. Open VS Code and Install the most important extensions as below.

Install the C/C+ extension: Open Visual Studio Code, click on the 

Extention Icon VS Code
Extensions icon on the left-side panel and search for the "C/C++" extension. 

C/C++ Extention Installation

Install the extension and reload Visual Studio Code.

Install Code Runner extension: Again search for the extension named "Code Runner" 

Code Runner ext. Setting
After installation go to the "Extention Setting" 
Code Runner terminal setting

Scroll down and look for the "Code-runner: Run In Terminal" or Simply search by
"@ext:formulahendry.code-runner"
. Make sure the option has a tick mark on it.

Install GCC compiler: To compile and run C and C++ programs, you need to install a compiler. GCC (GNU Compiler Collection) is a free and open-source compiler that can be used on both Windows and Mac. I recommend you download (MinGW - Minimalist GNU for Windows).

After downloading "MinGW - Minimalist GNU for Windows" Run the Program as Administrator

Step-1: MinGW Installation Screen
Click the Install button.
Step-2: MinGW Installation Path
Please do not change the MinGW path leave it as it is! It must be on the default C:\MinGW path.
Step-3: MinGW Installation Completion
Congratulation! Our MinGW program installation has been completed. Now you have to manually select the packages you want to install.
Step-4: MinGW Package Installation
I recommend you select all the packages and click on Installation and then Apply Changes.
This process will take some time. 
Now we have to set the environment for windows. Now Right Click on the This PC 
Step-5: This PC
Now after Right Click you'll see some options below 👇
Step-6: Default Menus
Click on the Properties. After that, a popup window will come forward
Step-7: Advanced System Settings
Now click on the Advanced system settings. You will see the system properties window.
Step-8: Environment Variables
Click on the Environment Variables
Step-9: System Variable Paths
Be careful you must double click only on the System variables Path. After double click you  will see this window.
Step-10: Edit Environment Variable
Now you have to add the MinGW compiler to the system variables. For that goto the This PC > Local Disk (C:) > MinGW > Bin
Step-11: Local Disk (C:)
Click on Local Disk (C:) 
Step-12: MinGW Path
Select the MinGW folder
Step-13: MinGW Bin Path (1)

Step forward to the bin folder
Step-14: MinGW Bin Path (2)

You will see all kinds of bin files in this folder. Now copy the path.
Step-15: MinGW Bin Path (3)
Single-click on the top of the path and press Ctrl + C from your keyboard to copy the path. (Example: C:\MinGW\bin)
Step-16: Edit Environment Variable

Now go back to the Edit environment variable and click the New option top of the menu. 
Step-17: Add New Path
Paste the copied path
C:\MinGW\bin
to that and you will see this as inserted. 
Step-18: Click OK


Now click OK
Step-19: Click OK
Click OK again. 
Step-20: Click OK

After clicking OK. Now simply restart your PC.
Step-21: Restart the PC

Skip the #OnWindows step below if you've already installed "MinGW - Minimalist GNU for Windows" successfully. 


On Windows:

If you counter any error with the "MinGW - Minimalist GNU for Windows" compiler then go through the other version of the MinGW compiler installation steps below. 

Download MinGW-w64 from Package Manager or MSYS2.

MinGW: Choose the x86_64-posix-seh architecture and install the software.

or

MSYS2: Download the installer: msys2-x86_64-20230127.exe

Add MinGW to your PATH environment variable.

On Mac:

Install Xcode from the App Store.

Open Terminal and type xcode-select --install.

Configure Visual Studio Code for C/C++ programming:

Open Visual Studio Code and click on the File menu.

Click on the Preferences option, then Settings.

In the search bar, type "C++".

In the C++: Environment section, add the path to your GCC compiler.

On Windows: "C:/Program Files (x86)/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/bin"

On Mac: "/usr/bin"

Create a new C/C++ file:

Click on the File menu, then New File.

Save the file with a .cpp or .c extension.

Compile and run C/C++ programs:

To compile the code, press Ctrl + Shift + B (Windows) or Cmd + Shift + B (Mac).

To run the code, press F5 and choose the "C++ (GCC) [default]" option.

That's it! You're ready to start coding in C and C++ with Visual Studio Code.  👨‍💻

A+A-

6 تعليقات

Write your comment below.

Enter the URL of the Image or Code Snippet, or Quote, then click the copy button you want to post. Copy the parsed result and paste it into the comments field.


A perfect massage - feel fantastic. Spamming is strongly prohibited!

  1. ভিডিও টিউটোরিয়াল দিলে আরো সহজে বুঝা যেত। কিন্তু এভাবে করার পরও সেটিং করতে পেরেছি। ধন্যবাদ ❤️️
  2. Thanks! Worked for me
  3. Maraming salamat. Ang tutorial na ito ay mas mahusay kaysa sa isang youtube video tutorial. Talagang madaling maunawaan.
  4. Thanks a lot. It worked for me perfectly.
  5. Great article! 👍 The instructions are clear and easy to follow, making it simple to set up Visual Studio Code for C and C++ programming. The article provides step-by-step guidance on installing the necessary extensions, such as the Microsoft C/C++ extension, for cross-platform development. It also explains how to install a C++ compiler, like MinGW, and configure it properly by adding the compiler to the system path. The article even includes a "Hello World" example to test the setup and provides tutorials for different platforms. Overall, it's a comprehensive guide that covers all the essential steps to get started with C and C++ programming in Visual Studio Code. 🖥️💻
  6. 🤓
Cookie Consent
We serve cookies on this site to analyze traffic, remember your preferences, and optimize your experience.
Oops!
It seems there is something wrong with your internet connection. Please connect to the internet and start browsing again.
AdBlock Detected!
We have detected that you are using adblocking plugin in your browser.
The revenue we earn by the advertisements is used to manage this website, we request you to whitelist our website in your adblocking plugin.
Site is Blocked
Sorry! This site is not available in your country.
error: Content is protected !!