GNU C++ compiler g++

Where to get?

This compiler is the easiest to get. First of all it's free, Yes, you don't have to pay for it. But, mostly it's available on Unix/Linux computers. If you have an access to suah a computer, then most probably you already have g++ compiler installed. However, if you are a Windows user you still can get one. To do that you need to install CygWin a Linux emulator for Windows computers. Honestly, we think that Unix/Linux is the best operating system to learn C/C++ and we'd recommend you at least try to play with it. It's just an opinion, though.

How to start?

If you have CygWin installed (or Unix/Linux computer available), then working with g++ would be pretty much like working with command line versions of Visual C++ or C++ Builder. All you need to do is the following:
  1. Create a directory for your new project
    mkdir work
  2. Go to the new directory
    cd work
  3. Create a text file containing the program (use any text editor)
    notepad main.cpp
    I was working in CygWin and used the usual Windows Notepad
  4. Once you created the file compile it with
    g++ main.cpp
    or g++ main.cpp -o main.exe
    The diffrence between this two commands is the first command will create file a.out for Unix/Linux, a.exe for CygWin and the second one will create file main.exe.
  5. Run the built program typing (I used the second command and created main.exe file)
    ./main.exe:
    Note: in my example I used the following code:
    #include <iostream.h>
    
    int main(void)
    {
       cout<<"Hello\n";
       return 0;
    }
    	  
    For your testing I'd suggest using a more sofisticated example:
    #include <iostream.h>
    
    int main(void)
    {
       int  a, b;
       char c;
       cout<<"Enter the first number a = ";
       cin>>a;
       cout<<"Enter the second number b = ";
       cin>>b;
       cout<<"You entered:\n a = "<<a<<"\n b = "<<b<<"\n";
       cout<<"The ir sum is a+b = "<<a+b<<"\n";
       cout<<"Type 'Q' and press enter to quit\n";
       cin>>c;
       return 0;
    }