We are going to write our first program, compile and run it under different operating systems. As is the convention our first program is going to print "Hello World" to the console and that's all it does.
On the Windows operating system we have many options in order to compile and run it.
Cygwin
One is to install the Cygwin software from the site:
Choose the "g++" compiler and the "make" utility from the options when installing. For a text editor we have many options available . One editor is "Textpad" that can be downloaded from the site:
You should also download the syntax definition file from the "Textpad" site for C++ language. That will enable the syntax coloring .
Eclipse and Netbeans
Other IDE environments that can be installed are Eclipse and Netbeans but these require a compiler such as "g++" to be installed separately.
Microsoft Visual Studio
Microsoft has Visual Studio that is a tool that can be used to compile different languages including C++. Microsoft has an IDE called "Visual Studio Express" that can be downloaded for free. There are some restrictions on this particular version but it can be used for learning purposes.
On the Mac there is software by Apple called Xcode . You need an Apple developer account and it's free. Apple is based on the Unix system and the same commands can be used from the Terminal window.
Unix
On a Unix system open up the terminal window and type:
g++
If you get a reply stating that there are no source files then g++ is already installed. If you get a reply that the command is not found then you have to install the C++ compiler. This depends on the kind of Unix system you have but the GNU compiler is usually available and free.
Compiling
File: "hello.cpp"
#include <iostream>using namespace std ;int main(){ cout << "Hello World." << endl ;}
To compile the above program we can simply do:
g++ hello.cpp
$ ./a.exe
Hello World.
On your system the default executable might be "a.out" . We can specify our own executable name with the command.
$ g++ -o hello.exe hello.cpp
$ ./hello.exe
Hello World.