+ 3
8th Jul 2019, 10:02 AM
Angus Mckinnon Young
Angus Mckinnon Young - avatar
6 Answers
+ 5
endl stands for end line, and if you didn’t put using namespace std in the top of your code, you will need to write it as std::endl each time, but if you write using namespace std at the top, you can just write it as endl. \n is an equivalent to endl, but needs to be contained in a string. If you are all ready using a string, it might be more practical (or just faster) to use \n at the end of your string, like: cout << “hi\n” But if you are using a variable, for example: int x=3; cout << x << endl You will want to use endl so that the next cout doesn’t go on the same line, instead of writing cout << x << “\n”
9th Jul 2019, 9:54 PM
Tigrr
Tigrr - avatar
+ 13
It may be a constant with value "\n" which means new line
8th Jul 2019, 10:04 AM
Sarthak Pokhrel
Sarthak Pokhrel - avatar
+ 5
For those wondering what flushing the output buffer means : Sometimes, when you use cout, you may not see the desired output on your screen. If so, add the endl (or flush) to the end of your output. It will force the os to print the content of the said buffer. Tho, it might not be good for performance purposes.
8th Jul 2019, 6:45 PM
Drax
Drax - avatar
+ 4
It also flushes the output buffer.
8th Jul 2019, 10:05 AM
Sonic
Sonic - avatar
+ 3
/n
8th Jul 2019, 10:04 AM
Lexfuturorum
Lexfuturorum - avatar
+ 2
Dont forget this ;
8th Jul 2019, 10:35 AM
Rani Puspitasari
Rani Puspitasari - avatar