+ All Categories
Home > Engineering > Output in c++ (cout)

Output in c++ (cout)

Date post: 12-Apr-2017
Category:
Upload: ghada-shebl
View: 71 times
Download: 4 times
Share this document with a friend
9
Output in c ++
Transcript
Page 1: Output in c++ (cout)

Output in c++

Page 2: Output in c++ (cout)

Output is the things that appears on the console screen

What do you think we do in order to print something on the screen?

Page 3: Output in c++ (cout)

cout << ;

A key word that hastto be used in stuff on the screen This is called a semicolon

and is used to indicate the end of the statement

In this space between (cout) and (;) we write the thing that we want to print

Page 4: Output in c++ (cout)

Let’s try these codes:

cout << 3; cout << 3+4;

cout << 3*4; cout << 4/2;

cout << 4-3;

Note: I can print more than one thing with 1 coutcout << 3 << 6 << 2; Result : 362

Page 5: Output in c++ (cout)

If we want to print a word or a sentence we have to put it inside “ “ (double quotes).

cout << “Ghada;”

cout << “Hello World;”!

If I want to print a single character we have to put it inside ’ ‘ (single quotes).

cout << ‘a; ’ cout << ‘A;’

Page 6: Output in c++ (cout)

We know that if I said : cout << “Hello” <<“world ; ”The result printed on screen will be :Helloworld;

What if I want to make it (Hello world) with a space between the 2 words??

Answer:

cout << “Hello” << “ “ << “world; ”

Page 7: Output in c++ (cout)

Anything in a “” will be printed as it is, so when I put a space between “” it will be printed as a single spacebetween the 2 words

cout << “Hello” << “_” << “world;” Result : Hello_world

cout << “….” << “Hello” << “….” << “world;”.…“ << ” Result : …Hello…world…

Page 8: Output in c++ (cout)

cout << 3 + 4; cout << “3 + 4”;Result: Result:7 3 + 4

The operation is put inside ”“ so it is not treated as an operation,it is treated as a sentence which needs to be printed as it is.

A normal operation.So the value is calculatedand printed on the screen.

Page 9: Output in c++ (cout)

cout << “This is the first line;”cout << “This is the second line;”

Try these 2 lines of code and see what the output will look like.Result: This is the first lineThis is the second line

What if we want to print each statement in a separate line??cout << “This is the first line” << endl;

cout << “This is the second line;”Result: This is the first line

This is the second line

Prints a new line after printing the first statement


Recommended