Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn New Lines | Basics
Introduction to C++ | Mobile-Friendly

bookNew Lines

As it is mentioned before the object cout doesn’t give us the opportunity to start the message from a new line. So what should we do if we want to print the message or data to separate lines?

To insert a new line you can use endl manipulator:

12345678
#include <iostream> using namespace std; int main() { &nbsp;&nbsp;&nbsp;&nbsp; cout << "I love programming!" << endl; &nbsp;&nbsp;&nbsp;&nbsp; cout << "I love C++" << " and " << "Python!"; &nbsp;&nbsp;&nbsp;&nbsp; return 0; }
copy

As a more compact alternative to endl you can also use \n character:

12345678
#include <iostream> using namespace std; int main() { &nbsp&nbsp&nbsp&nbsp cout << "I love programming! \n" << endl; &nbsp&nbsp&nbsp&nbsp cout << "I love C++"; &nbsp&nbsp&nbsp&nbsp return 0; }
copy

To create a blank line just use twice character \n after each other.

If you want to insert double quote characters to your message you can also use here the backslash \".

question mark

What should we use to make a blank line between two other lines?

Select the correct answer

Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 1. ChapterΒ 3

Ask AI

expand

Ask AI

ChatGPT

Ask anything or try one of the suggested questions to begin our chat

Awesome!

Completion rate improved to 3.7

bookNew Lines

Swipe to show menu

As it is mentioned before the object cout doesn’t give us the opportunity to start the message from a new line. So what should we do if we want to print the message or data to separate lines?

To insert a new line you can use endl manipulator:

12345678
#include <iostream> using namespace std; int main() { &nbsp;&nbsp;&nbsp;&nbsp; cout << "I love programming!" << endl; &nbsp;&nbsp;&nbsp;&nbsp; cout << "I love C++" << " and " << "Python!"; &nbsp;&nbsp;&nbsp;&nbsp; return 0; }
copy

As a more compact alternative to endl you can also use \n character:

12345678
#include <iostream> using namespace std; int main() { &nbsp&nbsp&nbsp&nbsp cout << "I love programming! \n" << endl; &nbsp&nbsp&nbsp&nbsp cout << "I love C++"; &nbsp&nbsp&nbsp&nbsp return 0; }
copy

To create a blank line just use twice character \n after each other.

If you want to insert double quote characters to your message you can also use here the backslash \".

question mark

What should we use to make a blank line between two other lines?

Select the correct answer

Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 1. ChapterΒ 3
some-alt