How to run C++ Program in Visual studio code tutorial | Download and Setup C++ in VS Code 2024

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi everyone in this video I will be showing you  how to download and install Min GW and run your   first C++ program and also how to set  up visual studio code for C++ so let's get   started so just go to Google and type download  mingw you'll be getting this sourceforge.net and   here you will be having mingw just click on that  and here you can see that it has about 4 million   weekly downloads so it's completely trustable and  here we will also be having download button and   here also you'll be having the instructions for  downloading so just click on this download button   so the download is completed just click on open  and you'll be getting this mingw installation   manager setup just click on install here  you need to select the directory where you   want to install if you want to change it  you can just click on this change button   so I have changed the path and I'll just click  on continue and have these things checked okay   just click on continue and our download process  will first begin so once everything is downloaded   just click on continue and you'll be getting  this mingw installation manager over here   and in this we need to basically check all the  packages that we are going to install so I'm   going to just click on this checkbox thing I  need to click for mark for installation okay   come to the next one check it and click Mark for  installation so do this for everything except fortran   alright we don't need Fortran compiler so  just do that for everything except that if you   want you can also do that it's totally up to you  if you think you are going to work with a Fortran   in the future you can do that but except that I  will go for every other thing so once you're done   selecting you need to click on this installation  option and you have to click on apply changes   and here just click on apply so  the installation will begin now   once the installation is complete you will be  getting this message all changes were applied   successfully you may now close this dialog  box so I'll just close this and also I will   close our Mingw installation manager  so now we need to add the mingw path to our   environment variable so for this we need to go  to the folder where we have installed mingw so   for doing that the simplest way is just go  to search and just type Mingw you'll be   getting this mingw installation manager app  you want to just click on open file location   and here also you will be having this just right  click and just click on open file location again   so it will directly take you to the folder where  you have mingw and here in the top you can see   right minGW is there just click on that and here  you'll be having this bin and just select this   entire path I hope it made sense it's basically  the default folder where you have installed your   mingw in most of the cases it's going to be  C mingw and Bin all right so just select that   copy this Ctrl C and just go to search and now  type environment variables just click on open   and in this click on this environment variables go  to path click on edit path under system variables   click on new and just paste it it's going to be  local disk C or D MinGW slash bin all right so   I'm just clicking on OK everywhere yeah  here also and now go to search again and   this time we are going to type command prompt  and let me just now zoom in so it's going to be   and I will just type G++ space hyphen  hyphen version and if I just hit enter so we   will be getting this G++ Mingw version  over here so in case if you aren't getting this   and if you are getting G++ it's not  recognized or some kind of error it means   that you haven't added the right path to your  environment variable so make sure that you have   added the correct path there so now we are done  with the installation of the compiler so now   let's go and run our first C++ program so  just go to Google and type download visual studio   code you will be getting the first link over  here as code visual studio.com just click that   and here you will be having Visual Studio code  for different OS that is for Windows Linux and   Mac I am going to download it for Windows  so I'll just click on this Windows okay   so download will get automatically started so  it is about 88.8 MB in size so just be patient   so once the download is  complete just click on open   and you'll be getting like this license agreement  just click on accept you can just scroll down and   read it next so this is the location where Visual  Studio code will be installed so if you want you   can just browse and change the location I am  fine with the default one just click on next   and next as well and here you can like  create a desktop icon and it's always   good to have this one just check this okay  action to Windows Explorer yeah better to   give check everything and just click on next and  install such a simple installation process okay   yeah so once installation is done just click on  launch Visual Studio code and click on finish so this is the first interface that you  will be getting after you launch Visual   Studio code so you can like change the theme  there is light dark contrast light contrast   dark so after selecting the theme you'll  be having here file option at the top just   click that and let us just go and open a  folder so I'll directly go into desktop and   I will just right click and create a new  folder I will just name it as C++   project and I'll just click that folder and click  on select folder so now I will be inside that C++    folder and this folder is currently  empty it doesn't have any files inside that so   for creating a C++ program here at the  top near the folder name you'll be having new   file just select that and we just type the program  or the file name which is going to be new Pro dot   you need to give the extension as CPP for C++ and you'll be getting this small C++ icon over there and just hit enter and here you  can see we are getting at the top new Pro dot CPP   and we will also be getting the C++ here  like it has automatically detected our language   and also here you will be getting a pop-up saying  do you want to install the recommended C slash   C++ extension just click on install  and this C slash C++ extension pack   will get automatically installed and it is from  microsoft.com so it's absolutely legit and in   case if you aren't getting any pop-ups like  that you have to go to this extensions icon   and you need to just go to the search over here  remove everything and need to search for C++ and you'll be getting the first option as  that one and basically click on   install if you aren't getting any recommendation  pop-up like me so once you're done installing the   extension it's always good to you know close  and reopen your Visual Studio code so let me   just now close and open it again and next thing  is regarding the size of the font so just go to   this manage which will have a settings like icon  select that and you need to go to settings and   inside this you just change the font size okay you  can have 30 to 40 that's like quite a decent size   I would say and now let's begin to code so it's  going to be hash include we will be getting this   auto complete and intellisense once we are done  installing our necessary C++ extensions   and also restarting our Visual Studio code so you need to  to add this both it's going to be IO stream   and the next line is going to be using  namespace STD and it's going to be int Main   let me just have a cout and let me go  with hello C++ not the world   I am done with this now yeah saving it so there  are two ways to run this program and I will show   you both the ways so first way is through the  terminal so for opening the terminal what I   would recommend you to do is you'll be having this  file right you need to basically just right click   on it and in this you'll be having option called  as open in integrated terminal just click that   and the main thing that you need to note here is  that you need to have your C++ projects   path over here so here you can see right C++ project I am having this C++ project   over here and inside that folder only I'm having  my C++ file and program so you need to be   careful that you are inside that particular folder  okay make sure that you are doing this and after   that you need to run the command g++ space  your program name which is newpro in my case with   the extension so it's going to be dot CPP and  just hit enter so this will basically compile   our program and it will generate this output file  which is a DOT exe over here so for viewing this   output we need to just run this output file  so for doing that it's going to be dot slash a   and just hit enter so here you can see I'm  getting hello C++ so let's see the   second way let me just clear the terminal CLS  yeah so for the second way we need to have a   extension called as code Runner so again go to  extensions and this time you have to search for   code Runner yeah this one just select that and  you need to basically install this one so you can   see the number of downloads right I think it's  around 20 million so it's trustworthy and once   you're done again you need to just restart your  Visual Studio code so now I am done restarting my   visual studio code so now the main thing is that  you need to have two extensions one is this C++   extension pack and another thing is you need  to have code Runner and after doing these things   just close it here you will be having this  run code okay so you need to just click on   this run code and you'll be getting the  output over here hello C++ yeah   you just saw that right and in case we want to  make any changes I'll just go with hello world   and if I just save it you'll be having this  run Icon and near that you'll be having these   three dots I would recommend you to go with run  code okay don't click on debug or something just   click on run code and here you can see if I scroll  down I'm getting hello world in my output but now   you can see I am getting the output in my output  console I'm not getting in my terminal so what if   you want to view the output in the terminal when  you are clicking on run so for doing that you   need to go to file and you here you'll be having  option called as preferences and you have to go   to settings and you will be getting the settings  over here and just click on extensions and in the   extensions you will be having something called as  run code configuration click that just scroll down   and somewhere if you scroll down slowly you'll  be having this run in terminal yeah whether to   run code in integrated terminal you need to just  check this one alright and just close this and   no need to restart your vs code now all right and  if I just know I think I can directly click on run   yeah this is just run code so I'll just click on  run code and here you can see right I'm getting   the output in my terminal itself and it is by  default run code so if it's not default by run   code you want to just click on this okay so that's  it guys this is basically how you configure Visual   Studio code for running your first C++  program so I hope you would have found this video   useful do check the playlist of my channel I've  done a ton of C++ programming tutorials   as well as programming videos in C C++  Java python node.js right JS mongodb MySQL   spring boot CRUD operations check them  out subscribe me thanks for watching
Info
Channel: United Top Tech
Views: 65,847
Rating: undefined out of 5
Keywords: how to run c++ in visual studio code, C++ in vscode, C++ Programming, Set Up Visual Studio Code for C++, C++ Compiler, Mingw c++ compiler vscode, run c++ vs code, setup visual studio code for c++ programmin, how to configure visual studio code for c++ programming, c++ tutorial, c++ tutorial for beginners
Id: pJ7iOcxfpEQ
Channel Id: undefined
Length: 12min 14sec (734 seconds)
Published: Wed Aug 02 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.