PDA

View Full Version : C++ Tutorial The Famous Hello World Program



minaadel1994
11-03-2008, 02:22 PM
Hi guys i wanted to make a tut a long time ago but ive ben lazzy :D!... srry though! anyways to start off with C++ u need a compiler i s***est Bloodshed-devC++ its beginner friendly :D now lets get started shall we... once u get the compiler u go to project - console app - and u wrote the following
NOTE : // is a comment , the compiler ignores it


#include<iostream> //preprocessor

using namespace std; //it declares cout and cin.. (explaining later on)
//Some people use std:: instead
// before each function examples comming later on

int main () // its where the code gets executed (the main function)
{
cout<<"Hello World"; //it basicly prints Hello world to the screen
cin.get(); // it prevents the program from crashing
}


the preprocessor declares functions used in later (ex:cout in this prog)
and using namespace std; kinda does the same thing but if u aint gonna put it the program will be written like this :


#include<iostream>

int main()
{
std::cout<<"Hello World"; //just a short example
}


NOTE : Never forget the semicolon , This ";" is very important , it tells the compiler that the function ends there
and if ur gonna write multiple stuff on the screen use endl
EX:


#include<iostream>

using namespace std;

int main()
{
cout<<"Hello World!" <<endl; // means new line ...
cout<<"Hello Again!" ;
cin.get();
}


Well thats it for now ... i'll be explaining more later on
and if u find any mistakes feel free to correct me :-)
hope u enjoyed it!

Happy programing!