Thread overview | ||||||
---|---|---|---|---|---|---|
|
March 25, 2005 write and read in one line | ||||
---|---|---|---|---|
| ||||
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 Re: write and read in one line | ||||
---|---|---|---|---|
| ||||
Posted in reply to Manfred Hansen | > 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 Re: write and read in one line | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ben Hinkle | 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 Re: write and read in one line | ||||
---|---|---|---|---|
| ||||
Posted in reply to Manfred Hansen | 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.
|
Copyright © 1999-2021 by the D Language Foundation