A basic introduction to the most basic elements of C++
This tutorial was designed for Visual C++ 6.0, but it should work with any other ANSI comptible IDE. We will now create a Hello World program in C++ and explain every line of code along with it.
Code:
#include <iostream>
using namespace std;
int main()
{
cout << "Hello World";
return 0;
}
Lets start with the first line. iostream is a library that is standard in c++. Libraries are usually a set of classes that define what certain objects do. In this example, the library "iostream" is needed for the "cout" (console out) function.
Since we can create other functions named "cout", line 2 defines that we are not using our own cout function, but the Standard set of namespace functions.
Let's look at line 4:
Code:
int main()
{
return 0;
}
int main() is defining a function named "main". The "int" means that this function will return an integer. When the program runs and completes, it will "return 0" and the program will be complete.
Now let's look at line 6:
Code:
cout << "Hello World";
cout is a function that will print text to the console screen. Each statement should always end with a ";" in c++. ( much similar to other languages )
This is a pretty basic tutorial but important to understand before you move on.