Thread overview
write and read in one line
Mar 25, 2005
Manfred Hansen
Mar 25, 2005
Ben Hinkle
Mar 25, 2005
Manfred Hansen
Mar 25, 2005
Georg Wrede
March 25, 2005
Hello,


import std.stdio;
import std.math;
import std.conv;
import std.stream;
import std.c.stdio;

void main() {
        int r;

        while(1) {
                writef("Bitte geben Sie den Radius ein ");
                //flush(stdout); // ???
                r = toInt(std.stream.stdin.readLine());
                if (r == 0) {
                        break;
                }
                writefln("Die Kreisflaeche betraegt %f",PI * r * r);

        }
}

That is the output from the Programm:
hansen@manni-lx:~/dd$ ./abbruch
3
Bitte geben Sie den Radius ein Die Kreisflaeche betraegt 28.274334


You see the "Bitte geben Sie den Radius ein" comes after the readline function. I try to solve this with flush but without success.

Manfred

March 25, 2005
>                writef("Bitte geben Sie den Radius ein ");
>                //flush(stdout); // ???
>                r = toInt(std.stream.stdin.readLine());

Flushing should work but I'm surprised you don't have to qualify stdout since there are two stdouts: one in std.c.stdio and one in std.stream. You could also not import std.stdio and just use std.stream and replace "writef(...)" with "stdout.writef(...)".

hope that helps,
-Ben


March 25, 2005
Ben Hinkle wrote:

>>                writef("Bitte geben Sie den Radius ein ");
>>                //flush(stdout); // ???
>>                r = toInt(std.stream.stdin.readLine());
> 
> Flushing should work but I'm surprised you don't have to qualify stdout since there are two stdouts: one in std.c.stdio and one in std.stream. You could also not import std.stdio and just use std.stream and replace "writef(...)" with "stdout.writef(...)".
> 
> hope that helps,
Yes

Manfred
March 25, 2005
Manfred Hansen wrote:
> Ben Hinkle wrote:
> 
> 
>>>               writef("Bitte geben Sie den Radius ein ");
>>>               //flush(stdout); // ???
>>>               r = toInt(std.stream.stdin.readLine());
>>
>>Flushing should work but I'm surprised you don't have to qualify stdout
>>since there are two stdouts: one in std.c.stdio and one in std.stream. You

Could it be because stdout is a pre-opened file handle, and thus not package dependent?

I.e. flush(stdout) uses the file handle (of which there only should be one), while having to write "std.stream.stdin..." is a function in a specific package.