MTH4300 Home

Preparing Windows Computers for C++ Programming

1. Dual view

Dual view is a setup where:

Remark. On Mac, the File Explorer equivalent is the app called Finder.

2. Dual View on Windows

2.1 Opening File Explorer

The first step is to open the File Explorer. Many computers have a desktop shortcut that opens File Explorer, usually pointing either to the root folder of the hard drive or to the documents folder. If such an icon is not available, the taskbar at the bottom of the screen often includes a shortcut to open File Explorer. Alternatively, you can access it from the main menu.

Screenshot of a Windows computer showing an open File Explorer window.

2.2 Starting the terminal

You can open the terminal by typing terminal into the search bar. The search bar is available from the main menu. When the black Terminal icon appears, click it to launch the program.

Screenshot of a Windows computer showing File Explorer and an open Terminal window.

2.3 Creation of folder

Give the command mkdir m4300 to create a folder that we will use to write our programs. Although the command was given to the Terminal, you will notice that the folder has appeared in File Explorer as well.

Screenshot of Windows desktop showing File Explorer and a Terminal window with commands 'mkdir m4300' and 'cd m4300' typed.

2.4 Entrance to the folder

Enter the newly created folder both in Terminal and in the File Explorer. Type the command cd m4300 in the Terminal. Double click on the folder m4300 in File Explorer.

Screenshot of a Windows desktop showing File Explorer and a Terminal window with the commands 'mkdir m4300' and 'cd m4300' typed. File Explorer now displays the empty folder named m4300.

2.5 Source file creation

Create the source file. Type the command echo > prog1.cpp in the Terminal. You may receive a question from the Terminal. Just click enter. You will notice a new file that appears in the File Explorer. The name of the file is prog1.cpp

Screenshot showing that a new file appears in File Explorer after the command 'echo > prog1.cpp' was executed in the Terminal window.

2.6 Typing of the source code

Move the mouse over to the File Explorer window. Right-click on the file prog1.cpp and choose to open the file with some simple text editor. Type the C++ source code as shown in the picture below. Make sure you save the file after the c++ source was typed in.

Screenshot of Windows desktop with File Explorer in the background, a Terminal window on top of it, and an active text editor in the foreground containing the source code for prog1.cpp.

2.7 Compiling the source code

Compile the source and create the binary by typing the following command in the terminal:

c++ prog1.cpp -o b1.exe 
A new binary file must appear in the File Explorer. If it did not, then there are two possible errors. The first possible error is that your computer does not have a c++ compiler. The second possibility is that there are errors and/or typos in your source file which caused the compiler to refuse to make the binary. For example, you typed the word int with capital I instead of lowercase i. Or, you typed long with capital L instead of lower-case L. C++ is case-sensitive. In either of the cases, the terminal has given you an error message that you need to investigate.

Screenshot of Windows desktop with File Explorer in the background and a Terminal window in the foreground showing the command 'c++ prog1.cpp -o b1.exe'. File Explorer now includes the compiled executable b1.exe.

2.8 Executing the binary

Execute the binary by typing one of the following two instructions: .\b1.exe or b1.exe. The program should print 70 in the terminal.

Screenshot of a Terminal window after executing '.\b1.exe', showing the program output '70', with File Explorer visible in the background.