Subscribe to Tutorial Feed

Flash and PHP Bible

The Flash and PHP Bible has been released! The book can be found on Amazon or wherever fine books are sold in your area.

The Flash and PHP Bible has a forum for quick support.

Scriptplayground » tutorials » c » Introduction to C++

Introduction to C++

Here is a simple introduction to C++ programming.

C++ is an object-oriented, low-level ANSI and ISO standard programming language. As a object-oriented language, C++ has the power exensibillty to write large-scale programs. There is a C++ compiler for every major OS, and they surpport the same C++ language. Such compilers are the following:

  • Bloodshed Dev-C++ C++ Compiler
  • Visual Studio.NET
  • Borland C++ Compiler

Once you have found the compiler you like, start to program, but first here is the basics.

1. Basics of C++. here is a simple but easy to start out program.

// my first program in C++ 

#include <iostream.h>

int main ()
  cout << "Hello World!";
  return 0;

// my first program in C++ -This is a comment line. All the lines beginning with two slash signs (//) are considered comments and do not have any effect on the behavior of the program.

#include <iostream.h>

Sentences that begin with a pound sign (#) are directives for the preprocessor. They are not executable code lines but indications for the compiler. In this case the sentence #include <iostream.h> tells the compiler's preprocessor to include the iostream standard header file. This specific file includes the declarations of the basic standard input-output library in C++, and it is included because its functionality is used later in the program.

int main ()

This line corresponds to the beginning of the main function declaration. The main function is the point by where all C++ programs begin their execution. It is independent of whether it is at the beginning, at the end or in the middle of the code - its content is always the first to be executed when a program starts. In addition, for that same reason, it is essential that all C++ programs have a main function.

cout << "Hello World";

This instruction does the most important thing in this program. cout is the standard output stream in C++ (usually the screen), and the full sentence inserts a sequence of characters (in this case "Hello World") into this output stream (the screen). cout is declared in the iostream.h header file, so in order to be able to use it that file must be included.

Notice that the sentence ends with a semicolon character (;). This character signifies the end of the instruction and must be included after every instruction in any C++ program (one of the most common errors of C++ programmers is indeed to forget to include a semicolon ; at the end of each instruction).

return 0;

The return instruction causes the main() function finish and return the code that the instruction is followed by, in this case 0. This it is most usual way to terminate a program that has not found any errors during its execution. As you will see in coming examples, all C++ programs end with a sentence similar to this.

This is all for now I will write more when i get time later peeps.

Follow Scriptplayground on Twitter (@scriptplay)

Comments: Introduction to C++

No Comments have been made. Wanna be the first?
Add a comment
The ability to add new comments has been disabled in this archived version.

Main | Tutorials | Articles