If you are familiar with C++ or know programming in C++, you can skip this tutorial.
Beginners always think higher and most of them just want a software that makes the perfect 3D game for them. That is IMPOSSIBLE, you can have my word for it. To make a perfect game, you always need to start from the first step. The first step in game making is to make a simple "Hello World" program.
You must have heard people say that BASIC or JAVA are the perfect languages for beginners. We will get to them later but for now we will focus on C++.
Tools Needed:
- Any C++ IDE (Integrated Development Environment) RECOMMENDED: Turbo C, C-Free, Microsoft Visual C++ (Click on the links to get the download).
I would recommend using Turbo C because I have not found a more simple IDE specially for a language like C++. And anyways it is lighter than the other two. So, I will be teaching from the Turbo C point of view.
Download and install Turbo C and open up (installation directory)\BIN\TC.exe. You will see a blue window with a grey one at bottom. The blue window is the editor where you write all your code. The grey one is the status window which shows you what the Turbo C engine is doing and what it has done.
Write down the following code (please don't copy and paste if you are serious about C++ programming). The lines are explained step by step at the end of the code. Write this code without the double quotes!
"//START
#include
#include
void main()
{
cout<<"Hello World!"<
cout<<"This is another line.";
getch();
}
//END"
Lets get to the explanation. The first line of the code that you see is //START. This line starts with two slashes i.e. //. These two slashes mean that the words after them (in the same line) are collectively a COMMENT. This means that the Turbo C engine (or any other that you are using) will ignore them. These are written so that readers of your script can get a better understanding of the code.
The next two lines use the word "#include". These are used when you want to include another file's code into your program to make your programming easier using pre-defined keywords (functions defined in the files you include). These files are called headers and they contain pre-defined keywords for you to use. These are included in the (installation directory)/include. In this program, "iostream.h" and "conio.h" are included, These two must be included in every program that is designed to get an input from user (more about that later) or to print output on the screen.
"void main()" simply means the main function of the program when it is executed. All programs must contain this because it is the root of all the functions of the program.
The curly brackets "{}" are used to enclose the code for a function, in this case the "main()" function.
'cout<<"Hello World!"' means to give the output "Hello World!" on the screen. "endl" means end line which is used to end the line to write the new string to the next line. "getch()" stands for get character. It is used for making the program wait before performing the next order till the user presses a key. Otherwise, the program just keeps executing the code without any pause. Well that's our first program in C++ for absolute beginners. If you have any problems, please write a comment on the topic. I will try my best to solve your problem. See you in the next tutorial.
No comments:
Post a Comment