C++ Tutorial – Hello World

So here is my first C++ Tutorial.

I will be using the portable DevCPP IDE for this tutorial.
Lets start by looking at the hello world program for the console:

I’m sure you’ve seen this C++ hello world many of times, here I will explain to you what everything does in this code.

This defines that we are using what is called a Header.
iostream is just a file that contains predefined declarations and variables so that we can start using certain members and methods. In this case, the iostream library (not the header file) allows us input and output functionality using streams.

using namespace std;

This means that if we use a member without declaring it’s namespace, then it will assume that we are referring to the namespace ‘std’ as default. Since all of the files in the C++ library declare their entities in the std namespace, it’s always a routine to add this at the top of your code. If we didn’t use this, we would have to declare every member manually by specifying it’s name space like this: std::MEMBERNAMEHERE

int main()
This defines our function that will return a value of an integer, following this we have our code block for this function inside { and }. It returns an integer because of the ‘int’ declaration type of the function and the name of this function is ‘main’. Inside the parenthesis we would declare variable names which would be the arguments passed to it when called but for now we don’t.

cout << "hello world" << endl;
You can guess that this is the part that writes hello world. cout stands for Console Out, it is a stream handle that we can write to which outputs to the console screen. Here we are writing the string hello world which is defined in double quotes as a string, then after that we write the object ‘endl’ to cout which means End Line.

return 0;
This like we said before, our function returns an integer so at the end of our function we place ‘return 0;’ to return an integer of 0 which means the execution was successful.

After that in DevCPP just hit Ctrl+F9 to compile then CD to the directory that you compiled it to and run your file from cmd. It should output ‘hello world’ then terminate back to cmd.

One thought on “C++ Tutorial – Hello World

  1. Pingback: Error during compiling C code that calls dll function ? [Solved … | DevBlogr

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: