Exercise 1
belly — Sat, 2011-03-05 08:45
This exercise has been designed to create and then compile your first C++ program as part of the basic “teachings” of using the GNU “g++” compiler.
In the tradition with initial programming, this exercise will focus on creating a “Hello World” C++ program.
A "Hello world" program is a computer program that prints out "Hello world" on a display device. It is typically one of the simplest programs possible in most programming languages. Therefore, by tradition, it often the first program taught in a beginning class on a particular language. It is also used to illustrate the most basic syntax of a programming language. Cited (http://en.wikipedia.org/wiki/Hello_world_program)
Therefore I would ask those interested to try out the following:Create a hello.cpp file using your favourite text editor containing the following:
#include <iostream>
using namespace std;
int main()
{
cout << "Hello World!" << endl;
return 0;
}
- Compile your newly created C++ program using the following command line syntax (note, if you don’t have g++ installed, you will need to install it)
g++ hello.cpp -o hello
- Then execute your newly compiled program using the following command:
./hello
- You should see the following output
$ g++ hello.cpp -o hello
$ ./hello
Hello World!
- Login to post comments