What is the difference between 1) \n and endl 2) cout and cin.. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

What is the difference between 1) \n and endl 2) cout and cin..

C++

14th May 2019, 9:07 PM
Zain Uddin Bangash
Zain Uddin Bangash - avatar
3 Answers
+ 4
As Diego said, using endl will flush the output buffer whereas using '\n' won't.
15th May 2019, 12:10 AM
Sonic
Sonic - avatar
+ 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.
14th May 2019, 9:14 PM
Diego
Diego - avatar
+ 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 😊
14th May 2019, 11:34 PM
Tahir Iqbal
Tahir Iqbal - avatar