What is difference between "\n" and "endl" | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 5

What is difference between "\n" and "endl"

8th Oct 2017, 3:14 AM
sukhchet
sukhchet - avatar
10 Answers
+ 10
"\n" can be a part of the string but "endl" is a separate thing. I can't think of anything else.
8th Oct 2017, 4:04 AM
Krishna Teja Yeluripati
Krishna Teja Yeluripati - avatar
+ 4
endl mainly used
10th Dec 2017, 10:29 AM
Vyshnav Vishnu
Vyshnav Vishnu - avatar
+ 2
Nothing that immediately comes to mind. I suppose endl; is easier to spot and read.
8th Oct 2017, 3:17 AM
LunarCoffee
LunarCoffee - avatar
+ 2
endl only exists in C++, "\n" works in many languages
8th Oct 2017, 4:14 AM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 2
\n is used while in programming c I know that about it. it is used to break line and start with new line
8th Oct 2017, 5:21 AM
Yesh Jadav
Yesh Jadav - avatar
+ 2
\n is an escape sequence, endl isn't.
8th Oct 2017, 5:41 AM
Aditya Saumya
Aditya Saumya - avatar
+ 2
Ace, I don't understand this: "flushes the output buffer", what does that mean?
8th Jul 2018, 1:13 AM
Eduardo Perez Regin
Eduardo Perez Regin - avatar
+ 2
Ace I see, but I have another question, when Do I need to use endl and \n? if I want a faster program can I use all the time \n? \n is slightly faster than endl, or is there a specific cases where I need to use \n and endl?
8th Jul 2018, 5:24 PM
Eduardo Perez Regin
Eduardo Perez Regin - avatar
+ 1
The main difference is hardcoding it in with "\n" assumes the line ending, thus good old Notepad for Windows sees it as one long line with an unknown character at the end of each line. Windows uses "\r\n" while modern Mac OSX as well as Linux / Unix uses "\n" (old Macs used "\r").
12th Jul 2018, 1:35 PM
Katie (Ctrl-Alt-Cuteness)
Katie (Ctrl-Alt-Cuteness) - avatar