0% found this document useful (0 votes)
15 views8 pages

C++ New Lines

Uploaded by

lovemation098
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views8 pages

C++ New Lines

Uploaded by

lovemation098
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

C++ New Lines

‹ Previous Next ›

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

Try it Yourself »
:
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;
}

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;

 } Menu   Log in

HOWTO Try it
W3.CSS
Yourself »C C++ C# BOOTSTRAP

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.

Examples of other valid escape sequences are:

Escape Sequence Description Try it

\t Creates a horizontal tab Try it

\\ Inserts a backslash character (\) Try it

\" Inserts a double quote character Try it


:
?
Exercise
Which character can be used to insert a new line in your output?

\c

\i

\n

\x

Submit Answer »

‹ Previous Next ›

Track your progress - it's free!

Sign Up Log in
:
ADVERTISEMENT

COLOR PICKER



ADVERTISEMENT
:
 PLUS SPACES GET CERTIFIED

FOR TEACHERS FOR BUSINESS

CONTACT US

Top Tutorials
HTML Tutorial
CSS Tutorial
JavaScript Tutorial
How To Tutorial
SQL Tutorial
Python Tutorial
W3.CSS Tutorial
Bootstrap Tutorial
PHP Tutorial
Java Tutorial
:
C++ Tutorial
jQuery Tutorial

Top References
HTML Reference
CSS Reference
JavaScript Reference
SQL Reference
Python Reference
W3.CSS Reference
Bootstrap Reference
PHP Reference
HTML Colors
Java Reference
Angular Reference
jQuery Reference

Top Examples Get Certified


HTML Examples HTML Certificate
CSS Examples CSS Certificate
JavaScript Examples JavaScript Certificate
How To Examples Front End Certificate
SQL Examples SQL Certificate
Python Examples Python Certificate
W3.CSS Examples PHP Certificate
Bootstrap Examples jQuery Certificate
PHP Examples Java Certificate
Java Examples C++ Certificate
XML Examples C# Certificate
jQuery Examples XML Certificate

    

FORUM ABOUT ACADEMY


W3Schools is optimized for learning and training. Examples might be
simplified to improve reading and learning.
Tutorials, references, and examples are constantly reviewed to avoid errors,
but we cannot warrant full correctness
of all content. While using W3Schools, you agree to have read and accepted
our terms of use, cookie and privacy policy.

Copyright 1999-2024 by Refsnes Data. All Rights Reserved. W3Schools is


Powered by W3.CSS.
:
:

You might also like