VSCode Setup
VSCode Setup
What is a Compiler?
Computers don’t understand English or any higher programming language like C++,
they only understand the language of zeros and ones (0101…) i.e. binary. Therefore,
we need a translator to translate our C++ code into machine-readable binary code.
This is the job of a compiler. We will use the MinGW compiler. It will convert your
.cpp file (which contains your C++ code) into an executable .exe file that you can run
on your CPU.
Note: If on pressing “Close” the setup says that packages will be discarded
then do step 6 again because some files were not downloaded.
9. Go to the directory where you installed MinGW and open “bin” folder
10. Now click on the top bar in the folder (Anywhere after bin)
14. Another window will open. On this window under the “System Variables”,
select “Path” and then press “Edit”
15. Another window will open. Click new and paste the copied directory and
press “Ok”
16. Now search cmd and open Command Prompt
17. Now to test if MinGW compiler was successfully installed type “gcc -v”
without the quotation marks in Command Prompt and press enter. If you
see “gcc is not recognized as an internal or external command” as the
output, then you have done something wrong while setting up the
environment variable
3. Select the directory where you want to install and press “Next”
4. Again press “Next”
5. Now check all the boxes MOST IMPORTANTLY the “Add to Path” box
and press “Next”
6. Now press “Install”
9. Search “C++” and click on the first search result (the result shown in
the image” and press “Install”
How to run C++ programs:
1. In VSCode go to “File” and click on “New File” and an editable text file will
open
6. Now type “g++ Hello.cpp -o Hello & Hello” and press enter.
g++ <FileName>.cpp -o <AnyName> & <TheNameUsed>
g++ Hello.cpp -o Hello will make an .exe file of name Hello, the & is used
when you are giving another command e.g. command 1 & command 2 here
command 1 will be executed and then command 2 will be executed. In our
case .exe file is generated and then our second command, Hello will give us
the output
How to setup C++ on Mac
5. Search “C++” and click on the first search result (the result shown in the image)
and press “Install”
6. Search “Code Runner” and click on the first search result (the result shown in the
image) and press “Install”
7. Now to open the terminal, click launchpad. Open others and now click on terminal.
8. Clang may already be installed on your Mac. To verify that it is, open a macOS
Terminal window and enter the following command: ‘clang –version’
12. Click “File” and then “New File” or command N and a new file will open
13. Click “File” and then “Save As” or command S and save the file in the directory
of your choice. While naming the file it is very important to add “.cpp” extension at
end of the filename!!! Or else the compiler wouldn’t know this is a C++ file L
14. Now time to write a few lines of code!
Write the code, then save using command S and then run the code.
The output will appear.
Excellent Job!!!