Does cout need to be terminated with a semicolon ?
- by Philippe Harewood
I am reading Bjarne Stroustrup's Programming : Principles and Practice Using C++
In the drill section for Chapter 2 it talks about various ways to look at typing errors when compiling the hello_world program
#include "std_lib_facilities.h"
int main() //C++ programs start by executing the function main
{
cout << "Hello, World!\n", // output "Hello, World!"
keep_window_open(); // wait for a character to be entered
return 0;
}
In particular this section asks:
Think of at least five more errors you
might have made typing in your
program (e.g. forget
keep_window_open(), leave the Caps
Lock key on while typing a word, or
type a comma instead of a semicolon)
and try each to see what happens when
you try to compile and run those
versions.
For the cout line, you can see that there is a comma instead of a semicolon.
This compiles and runs (for me). Is it making an assumption ( like in the javascript question: Why use semicolon? ) that the statement has been terminated ?
Because when I try for keep_terminal_open(); the compiler informs me of the semicolon exclusion.