0

C++ - Difference between endl and /n?

In C++, there's two ways for output to go to a new line, as far as I know: endl and /n. My question is this - are there any benefits to using one over the other, whether it be for optimizing code, better practical use, etc? I personally use << endl for going to a new line since when I'm doing bigger programs, it's easier on my eyes and helps me recognise new lines of output easier. TL;DR: Which is better for going to a new line in C++? endl or /n?

29th Nov 2017, 4:42 PM
Clearwater
Clearwater - avatar
3 Respuestas
+ 9
@Netkos please what does it mean to flush stream
29th Nov 2017, 8:17 PM
Justine Ogaraku
Justine Ogaraku - avatar
+ 5
endl = newline + flush stream \n = newline ^That's the difference between the two. If you don't need to flush the stream also, then just use \n. If you need to flush the stream also, then use endl.
29th Nov 2017, 4:58 PM
AgentSmith
- 4
endl is the recommended method. The other might not work on all systems because they use a different character for it.
29th Nov 2017, 4:53 PM
John Wells
John Wells - avatar