August 7th, 2013, 01:02 PM
Using endl in C++
So i am reading C++ primer and i saw that at the end of cout
they us endl i know its for flushing the buffer but is it needed.
Because in C the you flush the buffer input so a standard input function doesnt read the /n but do you need to do it in C++.
Thanks in advance.
August 7th, 2013, 02:21 PM
It is not for flushing the buffer, but rather for outputing a new line. It happens to also flush the buffer.
Originally Posted by CAAA
Whether it is necessary is system dependent, but since by default cout is synchronised with stdout and is almost certainly implemented using stdio, then if on your system you don't get output without flushing, but you don't want to output a newline, then you will need to independently flush the buffer. If you want the code to be system independent and portable, you should do that in any case.
std::cout << "Hello, World" << std::flush ;
Last edited by clifford; August 7th, 2013 at 02:24 PM.
August 7th, 2013, 07:11 PM
Thanks just wasnt sure if it was needed well now i know thanks to you.