Debugging: Finding errors

In C++, white space (spaces, new lines, and tabs) are ignored. Most of the time, anyplace that a space is allowed, you can use other white space.

Most modern compilers are single pass compilers. It makes one pass looking for errors and compiling. It may not discover an error until it finds something else.

In the illustration below there is no semicolon at the end of the cout statement. The compiler shows the next line as having an error because it discovered the error when it found something unexpected.


The cout statement could have been written as shown below:

cout << "Hello " << "world" << endl;

After cout there must be << but then it would accept a string, a variable, or the special symbol endl that stands for new line. But it will not accept the word system, so that is where the error is detected.

Notice the red squiggle under the word system, indicating it is an error. There is nothing wrong with this line! The error is in the previous line.

NEXT: Finding logic errors