This could be a stupid question and already answered before but what exactly do you mean by flushing the stream?
Printable View
This could be a stupid question and already answered before but what exactly do you mean by flushing the stream?
Forced the data to to be seen at the screen (usually data is accumulated in a buffer and sent to the screen simultaneously because sending data to the screen is very slow).
I'd write it as:
:DCode:#include<iostream>
using std::cout;
using std::endl;
int main()
{
cout <<
"#include<iostream>\n"
"\n"
"int main()\n"
"{\n"
"\tstd::cout << \"Hello, world!\" << std::endl\n"
"\n"
"\treturn 0;\n"
"}";
return 0;
}
Yes it would, since it would flush the output buffer.
Not to be rude and interrupt the two of you but do you mean that using "endl" would make a separate call to the standard library therefor making it more slow then using \n?
I believe so, yes, since std::endl is actually a function. Hence it would flush everytime endl is called. While if you use "\n" if would probably only flush once (after you've printed the whole thing).
Can't say I know all the details, but this is the principle, at least.
Yes, though the forced flushing of the output buffer when encountering std::endl is more likely to be the main factor in slowing down the overall speed of output.Quote:
Originally Posted by Kitt3n
Thanks for the explanation.