How to Compile your C/C++ code on the Visual Studio Code.

in GEMS4 years ago

Hello Everyone

As you know we have already learned the basics of c++ in our previous posts. The first tutorial on my account was C++ its because when you are completely new to programming it is recommended to learn a high-level language like c/c++. When you know these languages it is easy for you to switch languages. In previous tutorials, we used Dev C++ because we were not able to run our script on the VS code. SO in this post, I am going to fix the problem. We are going to configure the Visual Studio Code for C++. To compile our code on VS code we need to install few things and configure our setting a little bit so without wasting time let's get started.

First of all, let me show you what errors we are getting while compiling our c++ code on the Visual Studio Code.

image.png

I have a simple Hello World code on the VS code. But when I run it

image.png

It is tell me that 'g++' is not recognized as an internal or external command, operable program or batch file. Plus it has some problems as well.

image.png

We are going to fix them in this post. So follow my steps and in the end, we will able to compile our code on the Visual studio code

  • We need to install a software called minGW. Visit this site to download this.
  • To check whether you have the software installed or not open Command Prompt and type gcc --version

image.png

In my case, I don't have installed.

  • After downloading the file open it

image.png

  • click on the install then continue and it will start downloading the necessary files. Make sure you have working internet connection.

  • Once done downloading click on continue. On the next step select this option

image.png

  • In the menu at the top left corner, click on “Installation > Apply Changes”

image.png

  • Wait for movements. When it is done it you should see something like this

image.png

  • Click on the "Close the Dialog when activity is completed and wait for the window to be closed.

Now we need to include the directory where the C++ compiler is located the environment variable.

  • Go to Control panel Items and open "Advance System Settings".

image.png

  • Now click on "Envoirment Variabels".

image.png

Select the Path and click edit.

image.png

  • Click "New" paste thisC:\MinGW\bin and save it.

  • Let's check the version again

image.png

  • As you can see the minGW is installed. Now let's run the program again.

image.png

  • Install the code runner Extenstion as well if you don't have it.

image.png


I think this much is enough for today. Now if you like the post please upvote and comment if you want to give me some advise
ntitled-1.png

Sort:  

Congratulations @pakgamer! You have completed the following achievement on the Hive blockchain and have been rewarded with new badge(s) :

You received more than 3000 upvotes. Your next target is to reach 3250 upvotes.

You can view your badges on your board And compare to others on the Ranking
If you no longer want to receive notifications, reply to this comment with the word STOP

To support your work, I also upvoted your post!

Support the HiveBuzz project. Vote for our proposal!

Thanks for sharing your skill. You are doing great effort by sharing your knowledge of coding. We are looking for people like you in our community.
Your post has been curated with @gitplait community account because this is the kind of publications we like to see in our community.

Join our Community on Hive and Chat with us on Discord