This is the first part in a series of articles where I am going to teach you C++ programming basics. These articles will be more practical oriented, with less of theory and more explanation of code and code snippets. I think this is a better and easier way into the world of programming.
The compiler I am going to use is Turbo C++ Version 1.01 by Borland, now available free of cost at the Borland website. With little modifications, you can apply the same code to your favourite compiler.
So let's start with a basic program, to print the words - Hello World onto the screen.
Program Listing:-
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
cout<<"Hello World"<<endl;
getch();
}
The first two lines include the two header files, namely iostream.h (Input/Output Stream) and conio.h (Console Input Output).
void main() is the beginning of the main function, where execution starts. clrscr() and getch() both appear in conio.h, the former is used to clear the screen, while the latter to wait until the user inputs a character.
The line which actually prints the words is the 'cout' line. Note its particular syntax. It is a statement which is going to be used quite often in C++ programming. The word 'endl' is used to specify 'end line', for jumping to a new line after the words have been printed. The usage of 'endl' is pointless here and has been shown for educational purposes.
References:-
Computer Science C++ - Volume I and II
By Sumita Arora
Written by Rae (4 January 2005)
Rae is a Member of CAU Knowledge-Bank Tutorial Writers
This article was originally published by CyberArmy.net in the CyberArmy Library.
|
|