Setting up an offline programming environment for C++

Here are some resources for setting up an offline environment for programming in C++.

This is a two-part setup process. You will need to install a text editor (what you will use to write the code), and a compiler (translates the written code into computer-language). We are going to use Visual Studio Code for the text editor and MinGW for the compiler. Visual Studio Code is perfect for our tasks in CS 124 because it is a lightweight program, meaning it will run fast, and it doesn't have an overwhelming amount of features that we don't need.

As a warning, the process to get this going can take some time (30 min - 1 hour). It is somewhat confusing, especially if you are new to all of this. Review both the instructions for installing MinGW and configuring Visual Studio Code before you do anything, that way you know what to expect. Once you have reviewed them, do the process in the order I have listed the links.

Setup

Download Visual Studio Code

Install MinGW - You don't need to use all of the information on this page. Follow the instructions under the following headings: MinGW Installation Notes, Graphical User Interface Installer, Environment Settings. Be sure to click the link "mingw-get-setup.exe" under Graphical User Interface Installer in order to download the compiler.

Configure Visual Studio Code once you have installed MinGW. Again, you don't need to read all of this right now. All you have to do here is install the Microsoft C/C++ extension. This is explained right beneath the heading Getting Started.

After you have followed all of these steps, you should be good to go. Now let's test it!

Testing 

Now for the fun part. Hopefully. Create a new file to write a test program. Save it as a C++ file with a name of your choosing. I chose "hello". Now, as you write your program, it will highlight your code in various colors that correspond to the different parts of the program. Write a simple "Hello World" program like the one on page 16 of the textbook. Save the file again. This is what you should see at this point:


Navigate to the terminal View > Integrated Terminal


The terminal panel will appear at the bottom of VS Code. cmd should be selected from the drop-down menu in the top right corner of the terminal panel.


You can now enter commands into the terminal. Note that it displays the location that you have navigated to. Type g++ followed by the name of your file, including .cpp at the end, and hit the "enter" key to compile your code. This is the same command that you use in the Linux Lab. A blank line followed by a new prompt means it worked.


Typing g++ told the compiler to compile the code and create an executable. An executable is a file that is able to be run by a computer; it does an action. By default, the file it creates is called "a.exe". Using the command dir will show you a list of files in the current directory, including the newly created program. It will be overwritten the next time you run the compiler.


 Now, lets execute our program. Simply type the name of the file then hit enter. It worked!


You can rename your file with the following command rename <filename> <newfilename>


If you were able to compile and run your test program, then setup was successful. Otherwise, you'll get errors and all kinds of fun stuff. If you do experience problems of any sort, double check the instructions and then reach out to me via the comments or Facebook Messenger.




Comments