Minimal C++

If you are not learning C++, skip to the section about Fortran.

In this exercise you will create a simple C++ program, compile it, and execute it. For this purpose, you will use the emacs editor to create the source program. So start emacs with the file hello.cc.

   emacs hello.cc &
In the emacs window, copy the following program:
	#include <iostream>
	int main()
	{
	  std::cout << "Hello, world.\n"; 
	}
Be sure to get all of the punctuation right.

Then when you are satisfied that it is correct, save the file. Do not exit emacs yet, however. Instead, bring the terminal window into view again and check the file with more to be sure it is what you expected. Then compile it with the command

   g++ hello.cc -o hello
The command causes the program hello.cc to be compiled and linked. The result of this operation is placed in an executable file called hello.

If the compilation is unsuccessful, return to the emacs window and fix your program. Save your edits and then rerun the compilation.

When the compilation is successful, run your program with the command

   hello
The result should be the message, “Hello, world.”

When you are finished, exit emacs.

A little more information about the g++ command is found in the chapter “More Unix Utilities,”