Basic C++ Tutorial

  • November 1, 2007
  • Avatar for jacob
    Jacob
    Peddicord

We'd like to give our new category, Programming, a bit of love. So, we're going to have some C++ tutorials from the ground-up, starting with your classic Hello World.

This tutorial should work on any system with a C++ compiler. For Windows, try Dev-C++. Ubuntu and Debian users, install the package build-essential. Fire up your text editor or IDE and let's get going. The rest of this tutorial will be in the code comments (marked by /* */ and //) below; while you can copy them into your compiler if you want, they are not necessary.

I recommend manually typing in the code above, line by line (excluding the comments). This makes sure you are able to learn by doing and not just by seeing. Save the file you just wrote as test.cpp and then open a terminal (unless you are using Dev-C++, in which this can be accomplished by hitting Compile).

g++ -o test test.cpp

This invokes the compiler using the file test.cpp and outputs it as a test binary. To run your newly-made program:

./test

If it didn't compile correctly, check your error messages and look for common mistakes, such as a missing quote or semicolon. If it did work, congratulations! You've just written your very first C++ program. Subscribe to the Programming section for more tutorials like these in the future.

Avatar for jacob Jacob Peddicord

Home » Articles »