1

I am learning C++ and I want to know what is more efficient for debugging;

Is std::cout << "Test\n"; more efficient than std::cout << "Test" << std::endl?

What I am trying to say here is, is "<string>\n" more efficent then <string> << std::end;?

Randyka Yudhistira
  • 3,612
  • 1
  • 26
  • 41
iProgram
  • 6,057
  • 9
  • 39
  • 80
  • As stated in the dup, `endl` will flush the stream, and you'll pay for that – quantdev Feb 18 '15 at 14:21
  • 2
    "\n" may be more efficient, but when debugging, effective is a nicer trait. Having unflushed output makes tracing errors much harder. – molbdnilo Feb 18 '15 at 14:25
  • So `endl` is more reliable then do you mean? – iProgram Feb 18 '15 at 14:28
  • it has nothing to do with "reliablility". as he suggested, when debugging, prefer to flush. if you don't know what that means, look it up. – Karoly Horvath Feb 18 '15 at 14:31
  • 1
    @aPyDeveloper: It means the output will go straight to the console or wherever, whereas with `\n` it might sit around in a memory buffer for a while, and you might lose it if the program crashes soon after. But for debugging, you might want `cerr` not `cout`, which by default will flush after every operation. – Mike Seymour Feb 18 '15 at 14:32

0 Answers0