Puzzled | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
+ 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 Respostas
+ 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