Jun 6, 2012

C++/Cpp Hello World application for beginners

In cpp we start with:#include <iostream>
This include an c++ library.using namespace std;
This must be included to use the print functions(i/o) cout and cinint main(){#code here}
this is a function but not just an however function because it telle to the compiler that this is the main of our code, where the compiler should start.

To print something we must use cout just like thiscout << "Hello world!";
this print hello world on the cmd (command line).
But the cmd gets closed! yes it executes and the gets closed.
To stop that we must add:system("pause");

Ok stop talking! Lets get into real coding:

#include <iostream>

using namespace std;

int main(){cout << "Hello World!";system("pause");}
And what it prints is:

7 comments:

after system("PAUSE");you need to add return 0;in order to to tell the compiler what to return , in this case the code that you writed dont need it but , on other coding you need to add that line.Also as an alternative of system("pause");can include #include library than after main add int main(){ string exit;..............cin>>exit;

In some compilers or IDE's, system("pause") will not work if you will not #include on the header. For beginners who doesn't want to bother themselves on what to put on the header (the place where you typed #include , you can try this code:

NOTE: "//" - stands for one line comment

#include // header so that we can use "cout" function

int main() // main function. every program have a function like this.{cout << "Hello World!"; // "cout" command prints the words enclosed in the "" sign.cin.get(); // this makes the program wait for a return keysroke before moving to the next line.

return 0; // all is well command. think of it as a programming convention.}