Compile Errors

Compile-time errors can occur for any number of reasons. Usually they are a result of a typo or other inadvertent minor error. Some compilers will not only tell you what you did wrong, they'll point you to the exact place in your code where you made the mistake. And some will even suggest a remedy!

You can see how your compiler will react by intentionally putting an error into your program. If HELLO.CPP ran smoothly, edit it now and remove the closing brace on line 6. Your program will now look like Listing 1.2.

Listing 1.2. Demonstration of Compiler Error
0:  #include <iostream>
1:
2:  int main()
3:  {
4:      std::cout << "Hello World!\n";
5:      return 0;

Recompile your program and you will see an error that looks similar to

 Line Unit ...

Get Sams Teach Yourself C++ in 24 Hours, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.