On Tue, Dec 03, 2013 at 06:12:20PM +0100, Benji wrote:
> Hello,
> in order to have correctly displayed output (before reading
> something from stdin),
> I must call stdout.flush().
> Sometimes, it's really annoying, especially when it is necessarry to
> call it 10 times.
> 
> For example:
> write("Enter some string: ");
> stdout.flush();
> string a = readln();
> write("And again please: ");
> stdout.flush();
> string b = readln();
> ...
> 
> Is there any way to prevent this?

What about:

        void prompt(A...)(string fmt, A args)
        {
                writef(fmt, args);
                stdout.flush();
                return readln();
        }

        auto a = prompt("Enter your name: ");
        auto b = prompt("Enter your age: ").to!int;
        ... // etc.


T

-- 
If you think you are too small to make a difference, try sleeping in a closed 
room with a mosquito. -- Jan van Steenbergen

Reply via email to