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:


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


after you import libc:

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