Swift: How to flush the output of println on command line interface CLI

Just enable flush print all the time:

// -- Swift: clear output buffer for print all the time. Why is that not the default?
setbuf(__stdoutp, nil);

 

1. Testing:

If you have some print and/or println statementes in your code - these get's buffered.

Example:

1. print("Enter a name: ")

2. input user value

Output:

<--- just waiting for your input, after you hit ENTER, the text will appear:

"Enter name:"

It can be that you will be prompted for user input before the print statement get's printed on the screen. This is a bad thing. So execution is linear, but print and println use so called buffered outputs.

Swift missing feature: Why is this not just the default for command line interface applications?

 

Swift: How to flush the output of println on command line interface CLI

Helpful?

Leave a Reply

Your email address will not be published. Required fields are marked *