Breaking News

How to Install Compiler and write your first Program in C++

From post we are going to apply all the basic concepts that we have study in the previous posts. Here is the place where we are going to start to code practically so let us be together.
First of all we have to understand the environment where we are going to write our code, here we are going to use special program called Compiler.

What is a Compiler?
A compiler is a special program that processes statements written in a particular programming language by a programmer and turns them into machine language or code format that a computer's processor uses. There are different types of Compiler for C++ and I prefer to use Dev C++. If you need this Compiler, just go to google and search for it. The installation of this is very simple, just follow the following steps.
  1. Double click on it after download, you'll be asked to allow Software to make changes to you device, Click Yes.
  2. Select Language that you are using, then Click Ok.
  3. You'll see the License Agreement dialog, jus Agree by Clicking Agree button.
  4. Click Next button
  5. Select the destination folder, where you want your software to be installed. If you don't want to change Click Install button, but if you want to change Click Browse button then select the destination folder.
  6. Wait the installation to complete. It take some time.
  7. Finally, Click Finish button.
After the Installation process, now go to shortcut icon of this Compiler and open it. To open your File(Worksheet) do the following.
  • On Menu Bar, Click on File -> New -> Source File. Or Press Ctrl+N

Now we are ready to code.

Simple, let us write our first program that will display Hello World to the Screen.

Now, type the following piece of code.

#include <iostream>
using namespace std;
int main()
    cout << "Hello World";
    return 0;

Finally, save it by pressing Ctrl+S Or Click on File -> Save. Name it as Hello World Program.cpp (you can save with your name).

Description of the code.

#include <iostream>

This is the stream for Input and Output (io) means we can access those functions concerned with the input of data to the program and output them.

using namespace std;

A namespace is a form of scope in C++ that holds its own definitions for variables, functions, etc. Example, both cout and cin, along with some useful tokens like endl , are defined inside of std for use.

int main()

For this stage, just understand that this is the main function, in the coming posts I will tell you what is the meaning of this function and why is main.

cout << "Hello World";

Here, we have cout, this is called Built in Function, obtained from the library called iostream. As I told you, iostream is concerned with Input and Output so this function is here for Output purpose and its syntax is must be followed with double less than sign ( << ). And "Hello World" is the string information to be displayed on Screen.
Note: Any string value that you'll write in your source code must be inclosed in double quote ( " " ) and any character value that you'll write in your source code must be inclosed in single quote ( ' ' ).

return 0;

For this stage, just understand that this is return statement and its return value is zero.

Now, how to run it after finishing and saving?

First we have to check for syntax error as I told you in the previous post (Compile). So press F9 on your keyboard or Click the icon shown in the following picture labelled with number 1 (drawn number)
If you didn't get any error, now run it by pressing F10 on your keyboard or Click the icon shown in the following picture labelled with number 2 (drawn number).

Finally, black screen will appear with Hello World as our output.

We are done...!!!

I hope now you understand how to write a program in C++. Feel free to ask any question if you didn't understand then I can reply as faster as I can.

Please comment and share with your friends. Don't miss the following post where we will continue to learn different things and application of our previous basic concepts.

Thank you for reading, be blessed....!!!

No comments