Solutio in silico

C++ Preface: Setting Up Your Environment

In order to get up and running with C++ you will need at least two tools: a compiler and a text editor. First I'll briefly go over the purpose of these tools, then provide information to help you setup your own C++ programming environment.

Every program/application is stored on you computer (or mobile device) in machine language, which is what most people refer to as binary (only zeros and ones). Theoretically you could write an entire program in zeros and ones, but this would be extremely tedious and really easy to make mistakes. Fortunately, programming languages like C++ have been developed that allow us to express long combinations of binary using simple lines of text. The purpose then of a compiler is to convert these lines of text, stored in text files, into a binary program (or app). To edit these text files you'll need some kind of text editor, a program which allows you to open, edit, and save text files. A text editor is similar to a word processor (Microsoft Word, Apple Pages, etc.) but is often much less complicated, as you don't need many of the features that a word processor provides. Finally, to make things simpler many programs have been developed that combine a compiler and a text editor into a single application, often referred to as an integrated development environment, or IDE.

There are many compilers, text editors, and IDEs out there for you to use, and deciding which ones are "best" for you depends on you level of programming experience, the operating system you use, and some personal preferences. Since it would be difficult to provide a comprehensive tutorial for every one of these options, in this preface I'll merely provide lists of free programs of each type that you can use to setup your own C++ programming environment, along with my personal recommendations and tips. After you've chosen your setup you can test it using the text file (or source code) provided below.

Additional Recommendations and Tips

Integrated Development Environments (IDEs)

Compilers

Text Editors

Test Your Environment

To test your C++ environment, either copy and paste the code below into your text editor, or download the file using the link provided below, then open the file in your IDE (if you're using one). Don't worry if you can't understand any of the code yet, we'll cover that in the next lesson.

test.cpp - Click here to download
/* test.cpp
   August 16, 2015
   Steven Dolly
   This program tests to make sure the C++ compiler works. */

// This statement includes the iostream header file into the program.
#include <iostream>

// This statement tells the program to use the standard namespace.
using namespace std;

// This is the main function
int main(){

    // This statement prints "Hello World!" to the screen.
    cout << "Hello World!\n";

    // This statement ends the main function, returning a value of 0.
    return 0;
}

If everything works after you compile the file, you should see the phrase "Hello World!" printed to your computer screen (without the quotation marks) and you've made your first program! In the next lesson, we'll look at the code above and discuss the basic structure and syntax of a C++ program.