digitalmars.D.learn - write and read in one line
- Manfred Hansen <manfred toppoint.de> Mar 25 2005
- "Ben Hinkle" <ben.hinkle gmail.com> Mar 25 2005
- Manfred Hansen <manfred toppoint.de> Mar 25 2005
- Georg Wrede <georg.wrede nospam.org> Mar 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
Mar 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
Mar 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,
Manfred
Mar 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.
Mar 25 2005








Georg Wrede <georg.wrede nospam.org>