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?
4 Réponses
+ 9
@Netkos please what does it mean to flush stream
+ 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.
- 4
endl is the recommended method. The other might not work on all systems because they use a different character for it.