Hello and welcome, myself Rehan Ali, And..
today in this video I am gonna show you how can we configure our vs code for compiling
and running our c and c++ programs,
alright so lets get started... ok, I am assuming that you already have installed
the visual studio code or vs code in your computer,
if its not case, you can simply download it from vs code's official website, you can also
find the link in the desciption of ths video for the same. installtion process is very simple. now, after downloading and installing vs code,
you may find this vs code shortcut on your desktop from where you can open it and write
your code there. Now, I already have created one folder on
my desktop named Test and inside this folder, right click and choose option open with code,
its simply means that we are opennig our Test folder with vs code. this is completely upto you, you can save
your files anywhere on your pc and open it from there also. alright , so, first I'll create the file named
test.c that means we are creating source file of c language. and I also write some c code here. just for the side note, if you are opening
this vs code IDE first time and you also have the good internet connection. it may possible that vs code will automatically
show you one pop up at your bottom right screen here
for installing the c and c++ extention. you can click on that popup and install your
c and c++ extension from there. but you can also download it from here the
option extension from the view or you can simply click on this icon where you'll
find any extension of your choice if it is available. now simply type c here, you may find your
c and c++ extension listed here.. download and installed
it. it will take some time to install all the
tools related to c and c++. now for running our c programs or may be any
programs, we also need to install another extension that will allow us to run our code
in simple way. in the search box,
type code runner. and install this extension as well. now close this file and go to your explorer. right click in editor window and choose option
run code. here I am gettign some error,
that is directly related to our c and c++ compiler which is nothing but the gcc compiler,
its simly means that, gcc compiler is not installed on my machine,
you may also get the same error, but don't worry, we'll solve this together. for installing gcc compiler, simply click
on the link from the description labeled as MinGW. after opening it, you'll get interface something
like this. here download this file of 45 mega bytes.
as I already downloaded it. I'll use that file instead,
afetr downloading that file you will find this installation file, just click on it,
and run the installer, here choose the location, I'll install it in my c drives root folder,
simply type c:/ or you can also choose file location from here, choose your c drive and
click on extract button, it will extract all the requierd files from
this package, again for making this vedio shorter, I'll
show you the next step. alright,
now, after extracting, you will find this MinGW folder in your c drives root folder
as you can see here. click on it, and then click on bin folder. what actually we are gonna do here is that,
we'll set our environment variable, so that system will easily find this compiler from
anywhere in our system, in this case from our vs code terminal. alright, so just copy this path and click
on this pc here, now here in this blank space, right click
and select properties option, now click on advance system settings then
select environment variables, inside this click on path and then edit option,
now click on new and past your copied path here. now click ok for all the windows and close
these both windos. now again open vs code and run the code. I am getting same error again because our
changes has not been reflected, simply closed vs code and open it again to
reflect our changes. now when you right click and run your code,
you will see this output printed in the terminal, congratulations,
we successfully configured our vs code for run c and c++ programs,
but there is something that is missing here, that we also need to set,
by default code runner will not allow us to take input from the user,
consider this example, where I am asking user to Enter any number and using the scanf function
in c, if we now run this code,
there is no any response, it seems like screen has frozen,
so, now, for getting our input from the user, we need to enable run in terminal option in
the code runner extention. for that purpose, go to extension and search
for code runner that we installed earlier, click on this Icon button and then extension
settings option. scroll down it a bit, and find Run In Terminal
option there, here it is, just enabled it. that's it. now we can also take some inputs from the
user. close this file and lets close the vs code
itself. so that, whatever changes we made will reflect
properly. now again open vs code and run your code. thats it. now we have succefully configured our vs code
to write, compile and run any c program. alright. So....
if you like this video, pls hit that like button. if you are new on the channel,
don't forget to subscribe the channel and also click on the bell icon so that you will
not missed out any videos that I planning to upload in comming future. that being said,
I hope to see you in next video.