your image

C++ New Lines

W3 Schools
W3 Schools.com^
Related Topic
:- C++ language programming languages

C++ New Lines

PreviousNext

New Lines

To insert a new line, 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;
}

Try it Yourself »

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;
}

Try it Yourself »

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;
}

Try it Yourself »

Both \n and endl are used to break lines. However, \n is used more often and is the preferred way.

 

PreviousNext

 

 

NEW

We just launched
W3Schools videos

Explore now

COLOR PICKER

 

LIKE US

Comments