endl vs \n (New Line) in C++

In C++, endl and /n are used to break lines or move the cursor to a new line. Both endl and \n may seem to be similar but has distinct differences which we have explored in this article in depth.

endl

endl stands for end line. endl is a predefined object of ostream class . it is a manipulator used to insert a new line and flush the output buffer.

cout

Example 1:

#includeusing namesapce std;void main(){ cout

Output:

HELLOWORLD

In the above example, HELLO is displayed first and then using...

 •  0 comments  •  flag
Share on Twitter
Published on May 26, 2021 09:06
No comments have been added yet.