C++ New Lines
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
HOWTO Try it
W3.CSS
Yourself »C C++ C# BOOTSTRAP
Both \n and endl are used to break lines. However, \n is most used.
\c
\i
\n
\x
Submit Answer »
‹ Previous Next ›
Sign Up Log in
:
ADVERTISEMENT
COLOR PICKER
ADVERTISEMENT
:
PLUS SPACES GET CERTIFIED
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