digitalmars.D.learn - write and read in one line
- Manfred Hansen (25/25) Mar 25 2005 Hello,
- Ben Hinkle (6/9) Mar 25 2005 Flushing should work but I'm surprised you don't have to qualify stdout
- Manfred Hansen (3/13) Mar 25 2005 Yes
- Georg Wrede (6/15) Mar 25 2005 Could it be because stdout is a pre-opened file handle, and thus not
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:Yes Manfredwritef("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,
Mar 25 2005
Manfred Hansen wrote:Ben Hinkle wrote: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.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
Mar 25 2005