2

I have the following D program:

void main( string[] args )
{
    import core.thread, std.stdio;

    for ( int i = 10; i > 0; --i )
    {
        writeln( i );
        Thread.sleep(dur!"seconds"(1) );
    }
    writeln("Bang!");
}

It counts from 10 down to 1 and then outputs "Bang!". Between each output the program waits for the duration of one second. When I run this program in Eclipse (Eclipse Platform, Version: 3.8.1, Build id: debbuild) with the DDT plugin (Version: 0.8.1.v201309231) then the console output is as expected, but it apppears only until after the program has finished running.

When I start the same program from the console, then the program behaves as it should.

How can I fix that?

4

1 回答 1

7

Put stdout.flush() before the sleep line. stdout is buffered, so flush ensures it actually gets out to the device instead of waiting in the buffer.

于 2013-10-21T15:21:00.437 回答