How do I flush the stdout in Swift after a println
command?
That is, what is the Swift equivalent of fflush(stdout)
in C?
The flush argument of the print() function can be set to True to stop the function from buffering the output data and forcibly flush it. If the flush argument is set to True , the print() function will not buffer the data to increase the efficiency and will keep flushing it on each call.
Doing printf("Hello "); sleep(1); scanf("%c", &things); shows for me that indeed, with an interactive program scanf flushes stdout buffer.
Each stdout. write and print operation will be automatically flushed afterwards.
You can use
fflush(stdout)
after you import libc:
#if os(Linux)
import Glibc
#else
import Darwin.C
#endif
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With