This could be a stupid question and already answered before but what exactly do you mean by flushing the stream?
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:
Code:#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; }
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.Originally Posted by Kitt3n
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
Thanks for the explanation.