+ 1
What is the difference between 1) \n and endl 2) cout and cin..
C++
3 Answers
+ 4
As Diego said, using endl will flush the output buffer whereas using '\n' won't.
+ 2
1. From Matteo SeclĂŹ's comment on this lesson: https://www.sololearn.com/learn/CPlusPlus/1604/
You should point out that there is an important difference between endl and "\n".
- endl flushes the buffer, i.e. what you write after cout will be immediately printed on screen (along with all the other things in the buffer).
- "\n" doesn't flush the buffer, i.e. what you write after cout will be kept in a buffer and printed on screen only when the buffer accumulates enough data or when it encounters a endl or cin in the program.
This is not an issue when you print few lines on screen, but it can significantly slow down your program if you print many lines or if you often write on a file instead of writing on screen.
So, be sure to use endl only if you REALLY need to print that text immediately; otherwise, it's better to use "\n".
2. "cout" is for output, "cin" is for input.
+ 1
1)
"\n" --> is use for to go on next line
"endl" is same as "\n"...
But these statements are use in different programming languages...
2)
"cin & cout" --> is C++ built-in functions, use for to print and get the data...
Thanks đ