0

What's the difference between endl and \n

13th Sep 2016, 6:16 AM
Emmanuel Asakyi
Emmanuel Asakyi - avatar
3 ответов
+ 2
They both perform the same function, as Name Less has shown. std::endl has the added benefit of clearing the input stream buffer. Read up on this on Youtube, I'm not going to write paragraphs about it. But if you're simply printing out text on its own, I prefer to use \n, as it's quicker to write and isn't as many characters. If I'm dealing with a lot of different user inputs, I prefer to use std::endl, unless I don't want the buffer cleared; most of the time I probably do. If you're having some weird results where std::cin seems to be skipping, then likelyhood is there are things sitting in the buffer waiting to be used; you should probably flush it.
13th Sep 2016, 2:54 PM
Cohen Creber
Cohen Creber - avatar
+ 1
nothing really as they are the same but as an example the usage of it can help like this string example="this is an example!"; cout << "this is an example!\n"; //Here it is convenient. cout << example << endl; /* Here instead of righting a string for a /n you can use endl. */
13th Sep 2016, 6:37 AM
Name Less
Name Less - avatar
0
\n is the alternative of endl both perform the same operation..
25th Sep 2016, 7:23 AM
ANKUSH CHAUHAN
ANKUSH CHAUHAN - avatar