How to break a output line in C++

The cout operator does not insert a line break at the end of the output.
One way to print two lines is to use the endl manipulator, which will put in a line break.
For examle:

#include<iostream.h>
using namespace std;
int main()
{
     cout<<"Hello world"<<endl;
     cout<<"I am programmer";
     return 0;
}

Output:

Hello world
I am programmer

The new line character \n can be used as an alternative to endl.
The backslash(\) is called an escape character and indicates a special character.

For example:

{
    cout<<"Hello world\n";
    cout<<"I am programmer";
    return 0;
}

Output:

Hello world
I am programmer

Using a single cout statement with as many instances of \n as your program requuires will print out multiple lines of text.

{
    cout<<"Hello\n world\n I\n am\n programmer";
    return 0;
}

Output:

Hello
world
I
am
programmer

Share Tweet Send
0 Comments
Loading...
You've successfully subscribed to Developer Insider
Great! Next, complete checkout for full access to Developer Insider
Welcome back! You've successfully signed in
Success! Your account is fully activated, you now have access to all content.