+ 3

Puzzled

Why not use /n to go to the next line instead of using endl when they both mean the same thing 🤦

13th Dec 2018, 2:18 PM
Isaac Ndidi
Isaac Ndidi - avatar
2 Respuestas
+ 8
Isaac Ndidi both are not the same thing... \n doesn't flush the buffer of output. endl provides the new Line that DOES flush the buffer. To conclude, if you are sure that your code is not gonna stop executing abruptly, use \n nd finally flush the buffer... otherwise use endl for each attempt to write... endl is more expensive...
13th Dec 2018, 2:55 PM
Ketan Lalcheta
Ketan Lalcheta - avatar
+ 6
Very interesting! std::endl --> Inserts a newline character into the output sequence and flushes it. Flushing the output stream ensure us that everything has been written to output. So to recap, the std::endl does two things, std::cout << '\n' << std::flush; As you can see the difference between them boils down to additional housekeeping manipulator. _____ https://en.cppreference.com/w/cpp/io/manip/endl https://en.cppreference.com/w/cpp/io/manip/flush
13th Dec 2018, 2:55 PM
Babak
Babak - avatar