🔥Limited Offer: Get 50% OFFon AI & Full Stack Courses🔥
Back to C++ Notes
Topic #8

New Lines


New Lines

To insert a new line in your output, you can use the \n character:

Example

#include <iostream>
using namespace std;

int main() {

cout << "Hello World! \n";
  cout << "I am learning C++";
  return 0;
}

You can also use another << operator and place the \n character after the text, like this:

Example

#include <iostream>
using namespace std;

int main() {

cout << "Hello World!" << "\n";
  cout << "I am learning C++";
  return 0;
}

Tip: Two \n characters after each other will create a blank line:

Example

#include <iostream>
using namespace std;

int main() {

cout << "Hello World!" << "\n\n";
  cout << "I am learning C++";
  return 0;
}

Another way to insert a new line, is with the endl manipulator:

Example

#include <iostream>
using namespace std;

int main() {

cout << "Hello World!" << endl;
  cout << "I am learning C++";
  return 0;
}

Note: Both \n and endl are used to break lines. However, \n is most used. But what is \n exactly? The newline character (\n) is called an escape sequence, and it forces the cursor to change its position to the beginning of the next line on the screen. This results in a new line.

Escape sequences always starts with a backslash. Escape sequences are important when you want to output special characters. For example, if you insert a double quote (") wrongly in your code, the program will fail. However, you can add a backslash in front of it, and then the output will be as expected.

Examples of other valid escape sequences are: Escape Sequence Description Try it \t Creates a horizontal tab \ Inserts a backslash character () " Inserts a double quote character

Want to go beyond the notes?

Join CodingNow 2.0's C++ course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available

New Lines – FAQs

Quick answers about learning New Lines in C++.

This free note from CodingNow 2.0 explains New Lines in C++ — concept, syntax and worked code examples you can copy, run and revise before interviews.
Yes. Every C++ topic on CodingNow 2.0, including New Lines, is 100% free with no signup required.
With focused practice, most students grasp New Lines in 1–3 days from these notes; pairing it with CodingNow 2.0's mentor-led course takes you to job-ready depth faster.
Use the code examples in this note, then ask doubts for free on the CodingNow 2.0 Community (/community) — expert instructors answer within 24 hours.
WhatsApp
Call NowEnroll Now