LESSON # 1
I ignore the boring detail and explanation
just wait and I will show you how to write your first program in C++.
WHAT YOU NEED TO GET STARTED?
1. Text (Code) Editor
2. C++ Complier
|
But we can get these two in a
single software i.e. IDE (Integrated Development Environment). Remember that
we will use Dev-C++ (freeware) in our lessons, go ahead and download it from www.bloodshed.net. Now install Dev-C++
in your computer and get ready to type your first program.
|
YOUR FIRST “HELLO WORLD” PROGRAM
After installation open Dev-C++ and:
1. For creating a new
source file, Click -> File - > New -> Source
File
(Ctrl +N)
2. Type the following code in Dev- C++
editor.
using namespace std;
#include<iostream>
main()
{
cout<<"Hello World";
system("pause");
}
3. For saving source file,
Click->File->Save
4. To see the output,
Click ->Execute -> Compile & Run (Press
F9)
5. Press any to exit.
C++ Code
|
Explanation
|
using namespace std;
|
A feature from namespace that eliminates
extra code std::cout
|
#include<iostream>
|
This line include a header file “
isostream” from include folder which is available in Dev-C++ installation
directory.
|
main()
{
|
This
line determines the starting of the main program, each program must have a
main function
|
cout<<"Hello
World";
|
Displays
Hello World on the screen
|
system("pause");
|
Pauses
the program to see the output
|
}
|
Indicates
the end of main program
|
Output
|
|
Hello World
Press any key to continue . . .
|
|
Get involved, try this simple code yourself. If you have any
problem, write in the comments. I will try my best to answer.
CODE
IN ACTION
No comments:
Post a Comment