Printing Output

The cout object along with insertion operator is used to print text on the screen.

Note: cout is pronounced as "see-out".

If you want to print anything on screen you have to write cout, then insertion operator, then your text in double quotation marks in the main function.

Note: Do not forget to put ; at the end.

Adding line breaks

\n moves the cursor to the next line. It is used inside the quotation marks.

endl manipulator is also used to add line breaks. It is used outside the quotation marks.

Different Escape Sequences

Escape SequenceCodeDescription
\ncout<<"\n";New line
\tcout<<"\t";Tab - prints four spaces
\acout<<"\a";Beep sound
\bcout<<"\b";Backspace
\fcout<<"\f";Form feed
\rcout<<"\r";Carriage return
\\cout<<"\\";It adds backslash
\'cout<<"\'";Single quote
\?cout<<"\?";Question mark
\0cout<<"\0";Null character

Printing Numbers

If we want to print numbers in C++, we store them in variables then print variables on screen. We will discuss about this in detail in variable section. Here is a brief description.

Note: If we write numbers in double quotes, these are not treated as numbers. Everything inside double quotation marks is a string literal which is text.

Practice Exercises

Complete these exercises to reinforce your learning and earn XP

Sign in to track your progress and earn XP!
Exercise 1 of 2Easy

Which of the following is a best practice in programming?

10 XP~2 min
Exercise 2 of 2Easy

Code that is easy to read and understand is called ___ code.

10 XP~2 min