C++ Intro…
By: Amin Patel
Before you write your first program. Start with a prayer to
God, that you “Succeed in learning C++”.
Now that all your hopes are high let us start. Please enter
the following code exactly as shown, without any questions. (This is to inform
you that the explanation will follow after the code.)
- #include
<iostream.h>
- int
main()
- {
- cout<<
“ What you do is what you get”;
- }
|
Although this may sound strange, once you compile
this program you are a programmer.
<Warning: The numbered indentation is not to be
included with the code while typing. It is only for your convenience>
Now let us read the first line. You read it as
“Hash/Pound include eye-oh-stream-dot-h”
Iostream: Input Output stream. Don’t learn
the definitions they automatically come to you.
|
You don’t pronounce the brackets while reading it loud,
but is it a part of the code.
.h: Dot h files are known as header files. We
place them in the beginning of the source code; it is like adding a DVD-Player
to your deck. You don’t create .h files for now, nor would you
add a DVD-Player to your deck each time you want to use it.
|
Iostream.h: Ok now you know what iostream
and dot h stand for. If the terms input & output
haven’t shed any light yet, keep reading. Iostream lets your
program accept info/data/content or publish the same to the screen.
|
Wait we are still on the first line. Read the first line of
source code again!
“Hash/Pound include eye-oh-stream-dot-h”
The Hash include is the standard form for telling the
compiler that you want to include the Iostream.h file.
Now on line 2 we have int main(). Int
is read as integer, read main() as main function. Without line 2 your program
cannot work. On line 3 and 5 you have these {} braces.
Between the 2 braces all your code fits in. Make sure you
enter line 4 exactly as it is. Pay attention to the punctuation.
Cout: See cout - It is the command with which you
display text onto the screen
The << on line 4 is the redirection symbol produced
on most keyboards by holding the shift key and pressing the comma key twice. The
text in between the quotation marks, in the case “What you do, is what you
get” is what shall be displayed onto the screen when you run the program.
Line 4 ends with a semi colon, don’t forget to type that,
almost all c++ statements end with that. Now you may finally link, build and
compile the code. Now you receive a message on a black terminal (Dos like):
“What you do is what you get”
Congrats - You are now officially a programmer and that too
c++.
I plan to write more tutorials when I can dedicate some
time after school. If you like this code please give me a good message. I do
need messages occasionally like “Thanks”, with all the pressure I face from
school. If you have gained knowledge from this tutorial please make me happy.
|