Isn't it a good idea to use a macro which replaces all the instances of endl with "\n" in all of my C++ programs to speed-up my code because doing so will stop unnecessary flushing of stdout?
Asking this because I have never seen anyone using such a macro.
Of course, in certain problems like the interactive ones, where I have to flush stdout, I will have to write fflush(stdout) separately.
What about just using "\n" where you need it?
Of course, but I'm habitual of writing endl to end lines. "Is there any advantage of using "\n" instead of using a macro?" — this is what I intended to ask. I'm sorry that my original post couldn't clarify my intention.
endl
flushes output and forces data being written to disk. And this can significantly slow your program if you are doing this a lot.Go to customtest and compare running time of this
and this
UPD: I've misread the question, sorry for pointing out things that are already clear.
if you use endl in interactive problems define may bite you.
Noam527 uses this.
Thanks, I'll use this too :-)
I started using this once I heard '\n' is quicker than endl, and I was used to write endl, but I had to write this template enough times that now I don't mind writing either of them, but now I'm used to this template so I'm still using endl because I keep forgetting to remove the #define, and if it's there then I should use it anyway.
It's all pointless.