Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 17

C++

Output Statements
Objectives
1.Understand the input output stream
2.Properly use output statements in a
program
3.Create a basic code that is able to
output text and variables.
C++ handles input and output through a stream.

Streams are a source or destination of characters


and are a mode of means of data transmission.

Input stream: The flow of the data is from the


user/device (ex. keyboard) to the main memory.
This topic will be discussed in the next lesson.

Output stream: The flow of the data is from the


main memory to the user/device (ex. display
screen).
The Input/output (I/O) features of C++ are in a library called iostream.

To use the functionality of this library, we need to include the iostream


header at the top of the code
Standard Output (cout)
This is used to produce output on the device, which is usually
the display screen.

The keyword used is cout which stands for Console OUTput,


meaning you are sending data to the console (device/display
screen) to output or display.
(This is usually pronounced as (see-out).
Standard Output(cout)
The cout keyword is paired with the insertion operator ( << ).

Strings, or series of characters that you want to display are


placed inside quotation marks (“ ”). When text is placed inside
quotation marks, it is displayed literally.
Standard Output(cout)
Standard Output(cout)
The insertion operator (<<) can also be used multiple times in
one statement to concatenate or combine multiple things to
output.
Standard Output(cout)
Using multiple cout statements doesn’t necessarily mean you will display
multiple lines of output.
For example, if you run the following code, you will only get one line of output.
Standard Output(cout)
If you want to display multiple lines
of output, you can use the endl
keyword to separate your text with a
line break.
The endl keyword signifies the end of
the line.
You may also use the new-line
character ( \n ) to insert a new line.
The new-line character is placed
inside the double quotation marks.
It is usually considered good
programming practice to add
endl or \n to the end of your
display lines.
Standard Output(cout)
You may also choose to use multiple insertion operators (<<) in a single
line of code to display multiple output lines.
Standard Output(cout)
To print the values of variables, you simply place the variable name after the
insertion operator WITHOUT quotation marks.
Practice Test
What is the expected output of the following snippets?
Practice Test
What is the expected output of the following snippets?
Practice Test
What is the expected output of the following snippets?
Practice Test
What is the expected output of the following snippets?

You might also like