How you set up to compile C++ programs depends on whether you are using Windows or Linux/Unix. This page describes the approach to use if you have a Windows machine. If you have a Linux/Unix machine, read this page instead.
There are many free C++ compilers that can be used with Windows. I am most familiar with Cygwin, available at
http://cygwin.com. These instructions assume you plan to downloaded this compiler, but it applies to many other compilers with small detail changes.
Download Cygwin, which is a self-extracting compressed file. Execute the file, follow the provided instructions, and the program will install itself.
Once you have installed the program, you should be able to execute it from a DOS window. Open a DOS window and type g++ -v to establish that the program has been installed and can be executed.
When I compile I use a batch file named gccp.bat with this content:
@echo off
echo compiling C++ using -ansi -pedantic-errors -Wall
g++ -ansi -pedantic-errors -Wall %1 %2 %3
If you want this batch file, simply copy it from this page and save it on your system in a file named gccp.bat. The file shold be located in a directory that is part of your path satement.
This batch file sets up the most strict ANSI standard compliance level, making it necessary for the programmer to pay attention to many compatibility and style issues. There are even some incompatibilities within Cygwin's own library routines, so this batch file may not always result in a successful compile even if your program is flawless. But in general, it is a good idea to establish high standards as a student, to become accustomed to good programming style.
If the Cygwin compiler is executed directly, without using the batch file, its behavior is more relaxed. This may sometimes be necessary.
Set up a convenient data directory in which to place your programs. Create a file named temp.cpp with this content:
#include <iostream>
using namespace std;
int main()
{
cout << "Hello World!" << endl;
return 0;
}
Again, you should be able to simply copy this little program from this page, and use a text editor to save it as temp.cpp.
Open a DOS window, change to the directory in which temp.cpp is located, and type this:
gccp temp.cpp
If you have not made any errors, the program will compile uneventfully, and a program file named a.exe will be created in the same directory.
Type a and press Enter. The program should run, and print Hello world! on the display.
This series of actions confirms that you have acquired a C++ compiler and it is working properly.
_____________________________________________________________