Module: (C++) Printing text to the screen


Problem

1/5

Hello, World!

Theory Click to read/hide

Hello world!

Let's take apart a program that prints the phrase "Hello, world!"
#include <iostream>
using namespace std;
int main()
{
   cout << "Hello, World!" << endl;  
   return 0;    
}

Let's analyze the program line by line
Directive #include <iostream> - (from input output stream) - standard library header file for work with input-output streams.

using namespace std; - Import the entire std namespace. This namespace contains all names from the C++ standard library.
 
The namespace is a declarative namespace within which various identifiers (names of types, functions, variables, etc.) are defined. 

Namespaces are used to organise code as logical groups and to avoid naming conflicts that can arise, particularly in cases where the code base includes several libraries. Standard input and output streams with the names cin and cout are described in the std area.
 
cout  <<  "Hello, World!" << endl;

cout is the name of the output stream, that is, the sequence of characters printed on the screen (the sequence of characters printed is written in inverted commas after the two triangular brackets <<).

It is customary to end the output with a line feed, for this purpose the function endl is used, which adds a newline character to the output and clears the buffer. Instead of endl you can directly output a line feed character ("\n"). 
The line feed will allow the next output or system messages to not be "glued" to the previous output.

Problem

Change "Hello, World!" on "Everybody loves kittens".