Swift: how to flush stdout after println?

3 Solutions Collect From Internet About “Swift: how to flush stdout after println?”

Maybe the following works (it compiles and builds, but I have not tried it, though):

Place #import <stdio.h> in your bridging header file

In your code use:

fflush(__stdoutp)

If you would like to flush to stdout automatically instead of manually calling fflush(__stdoutp) after every println, you can disable buffering altogether.

setbuf(__stdoutp, nil);

You can use

fflush(stdout)

after you import libc:

#if os(Linux)
    import Glibc
#else
    import Darwin.C
#endif