Do I need to end cout with a semicolon?

I am reading Bjarne Stroustrup Programming: principles and practice using C ++

The drill section for chapter 2 discusses various ways to view input errors when compiling a program. hello_world

#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 about at least five more mistakes you might have typed in a program (for example, forget keep_window_open()to leave the Lock key caps when entering a word or enter a comma instead of a semicolon) and try each one to see what happens when you try to compile and run these versions.

cout , .
( ). (, javascript: ?), ?

, keep_terminal_open();, .

+3
4

++ :

a, b;

"do a, , do b". :

a, b, c, (etc.), n;

, . , . , , :

for (int a = 0, b = 0; a < 100; a++, b++) {
    /* ... */
}

for " a, b".

, , cout. , , , .

+11

:

std::cout << "Hi world";

, , A,B,C, A B C , C .

:

std::cout << "Hi world", 3

:

std::cout << "Hi world", 3;

, . , , "".

, .

+3

,

+1

, ...

++, , , ...

#include <iostream>

int main()
{
    std::cout << 5, 2;    // outputs 5, complete line/statement evaluates to 2
    std::cout << '\n';
    std::cout << (5, 2);  // outputs 2 (5 is discarded), line evaluates to std::cout
    std::cout << '\n';
}

... "5" , A, "2" B.

- , keep_window_open() void, std::cout , , ...

std::cout << keep_window_open(); // can't compile if function return type is void

... , ...

std::cout << "Hello, World!\n",  // can compile because seen as two comma-separated
keep_window_open();              // subexpressions, so std::cout doesn't try to stream
                                 // a return value from keep_window_open().
0

Source: https://habr.com/ru/post/1785111/


All Articles