Displaying text on the screen


Let's analyze the program that displays the phrase "Hello, world!"
#include <iostream>
using namespace std;
main()
{
   cout<<"Hello, World!";      
}

We will analyze in order:
#include<iostream> - (Input Output stream ).

using namespace std;- this line says that the namespace std will be used, which defines the entire standard C ++ language library.
Here, the namespace is the scope of program objects, including variables. The std area describes standard input and output streams with the names cin and cout.

cout<<"Hello, World!";cout - it is the name of the output stream, it is the sequence of characters displayed on the screen (the sequence of characters that we output is written in quotation marks after two triangular brackets <<)

Screen Operator in C ++
Let's look at some of the features of the cin output statement.

1) You can write multiple output statements on the same line.
For example, a sequence of statements
cout << "текст1";
cout << "текст2";
can be written on one line
cout << "текст1" << "текст2";
In any case, the phrase text1 and text2 will be displayed on the same line

2)To transfer text to a new line, you can use the sequence of characters "\n", or the endl command;
The next two lines are identical in result. You can use any method
cout << "текст1 \n" << "текст2";  //обратите внимание "\n" записывается в кавычках
or
cout << "текст1 <<endl<< "текст2";
In the task, you will have to work with the source code of the program and force the computer to display certain information in the required form.

***Advanced material***
This material is intended for those wishing to learn the classical C language, and its differences from C ++
Knowledge of this material will help you in solving the olympiad problems

f you want to make the program faster (for example, when solving olympiad problems), then you can use the format output operator
In general, the formatted output to the screen is as follows:
printf("<format string>",<comma-separated variable names>);   //to work, you need to connect the stdio.h library
We will deal with variables in subsequent courses. Output variables is not always needed.

format string - this is a line that, in addition to text, can also contain special patterns, which we will also talk about in future courses.
In the general record, the characters <> are used to indicate that the information contained between them may be different, it all depends on the task. When recording a program, the <> characters are omitted.
If you write plain text inside a format string, it will be displayed on one line in the same way as it is written, on one line.
If we need to output something from a new line, then for this a special symbol \n is used in the place where the transition to a new line is planned.

For example,

printf("Everybody \nloves \nkitten");  

will output each word from a new line

 

Special characters

Many programming languages have special characters that just can not be output.
For example, commonly used special characters are backslash (\), quotation marks (") and apostrophes (')
Note that a regular slash (/) is not a special character!

To output such characters, we put a \ in front of each of them. That is, if we want to display the sign \, then in the output operator it is necessary to write \\

 
REMEMBER
To display the characters \, ", ', you must put a \ in front of them

Let's practice!