+ 3
endl?
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â
+ 13
It may be a constant with value "\n" which means new line
+ 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.
+ 4
It also flushes the output buffer.
+ 3
/n
+ 2
Dont forget this ;