Once I tried submitting a code on some coding platform my code gave TLE when I used endl but it passed the same code using “\n” does any one know what the difference between endl and \n?
-
Actually I also faced this issue when I started programming and got to know about this article where they have explained the same:
-
Endl in C++ is a manipulator or in simple terms a command. So when endl is encountered, the operating system will flush the output buffer and insert a new line while \n in C++ is a character taking 1 byte of memory and is appended to the existing bytes in the output buffer. Whenever the buffer is flushed, this 1 byte of memory corresponding to \n will result in a new line in the final display of bytes to the standard output.
1 Like
std::endl is slower than ‘\n’
1 Like