Lab #1, Wednesday 8/30

This lab is much shorter than usual since it is right after the first day of class. Normally you will be given several days in advance to read and prepare for the lab. In this case, it has been set up as a short activity to introduce you to the compilation environment.

Your goal is to compile and run the ubiquitious "hello, world" program in both Visual Studio and from the command line Ubuntu Linux. The code for the program is shown below:

#include <iostream>
using namespace std;
int main()
  cout << "hello, world" << endl;
  system("pause"); // Leave this line out on Unix

Visual Studio on Windows

Start Visual Studio 2015 and follow these steps to create a blank starter project:

  1. Run Visual Studio from the start menu (it is slow to start for the first time)
    1. Click "New Project", also under "File", "New", "Project"
    2. Select Visual C++ --> Win 32 --> Win32 Console Application.
    3. Note the location of the files on the disk for later.
    4. Pick a meaningful name for the project instead of ConsoleApplication.
    5. Click "OK".

    This should only apply to installing on your own computer, but if you can't find "Console Application" then see

  2. On the next screen, click "Next"
  3. On the Application Settings screen,click "Empty project" and then click "Finish"
  4. Right-click on Source Files and select "Add" --> "New Item"
    1. Select "C++ File"
    2. Accept the default name of Source.cpp if you like or change it to a name of your choice.
    3. Click "Add"
  5. Type your program into the editor window.
  6. Click the green triangle to compile and run the program. If you have errors they will show up in the bottom.

g++ on Linux (Ubuntu)

Follow these steps to edit and compile a C++ program from the command line in Linux.

  1. Run putty (or another ssh client). On the Windows machines in the lab you should find it from the start menu or if you search for putty using the search tool. You can also download it from
  2. Connect to host Note that if you are connecting from off-campus then you need to log in first using a VPN, which you can access from
  3. Your login username is your UA username (e.g. kjmock) and your default password is your student ID number (e.g. 30499999). When you type your password the input will not echo, so you'll be typing blind. The computer will still get your input though! When you log in you should be asked to change your password. It may first ask for your old password again, then your new password twice. After you change your password the window will close and you will need to log in again.
  4. A simple editor to type in your program is nano.
    1. To use nano to edit a file named "hello.cpp", type in: nano hello.cpp
    2. The nano editor will come up and you can type in your code. Use the arrow keys to move. Control-keys are listed at the bottom.
    3. Note that the editor is not a GUI window! You can't click or select text with the mouse. It is all keyboard controlled. If you are familiar with another editor, you can use that instead.
    4. See if you would like a tutorial on using nano.
  5. Type in the program (minus the system("pause") line) and press control-o, press Enter to save, then press control-x to exit.
  6. To compile type: g++ hello.cpp
  7. To run your program, type: ./a.out (note the leading dot)
  8. You can get a directory listing using the ls command. If you want a list of other commands, see The next lab will go into other linux commands in more detail.