Tuesday, February 3, 2009

Introduction to Programming :: C++

Generally the first thing students will write in any programming language will be "Hello World." The way to begin a C++ program is to first set up the structure of the program by writing the #include statements. An example would be iostream. This is the basic input output library in C++. Following the include statements add using namespace std;. Every element of the standard C++ library is declared within a namespace. Next write the beginning of the executed code. int main() is recognized to be the beginning of the executable code. Now that everything is set up coding can begin on the "Hello World" program. This following code uses the items mentioned above and cout which will be explained more in depth in future blogs but for the time being it is a simple way to output to the screen.

#include
using namespace std;

int main()
{
cout<<"Hello World"<<endl;
return 0;
}

The program should look similar to this. The only thing that should be displayed on the screen is "Hello World." A good rule to follow when writing programs is always write comments using // " comment here " while working on the code. This will help keep the program organized and easy to understand for the user.

No comments:

Post a Comment