Thread overview |
---|
April 29, 2017 User input; quick question. | ||||
---|---|---|---|---|
| ||||
import std.stdio; I am somewhat new to D, and I am trying to receive user input, like this, with a prompt: string str; writeln("Enter a string: "); str = readln; writeln(str); However, the prompt appears after I enter the input; any reason why? I've trawled the internet for a good hour, but I can't seem to find an answer. |
April 29, 2017 Re: User input; quick question. | ||||
---|---|---|---|---|
| ||||
Posted in reply to fred | On Saturday, 29 April 2017 at 21:09:13 UTC, fred wrote:
> import std.stdio;
>
> I am somewhat new to D, and I am trying to receive user input, like this, with a prompt:
>
> string str;
> writeln("Enter a string: ");
> str = readln;
> writeln(str);
>
> However, the prompt appears after I enter the input; any reason why?
>
> I've trawled the internet for a good hour, but I can't seem to find an answer.
Your code is correct, it's your terminal or whatever you use to see your program's output that doesn't flush stdout. You can force it though:
string str;
writeln("Enter a string: ");
stdout.flush;
str = readln;
write(str);
|
April 29, 2017 Re: User input; quick question. | ||||
---|---|---|---|---|
| ||||
Posted in reply to cym13 | On Saturday, 29 April 2017 at 21:18:27 UTC, cym13 wrote:
> On Saturday, 29 April 2017 at 21:09:13 UTC, fred wrote:
>> import std.stdio;
>>
>> I am somewhat new to D, and I am trying to receive user input, like this, with a prompt:
>>
>> string str;
>> writeln("Enter a string: ");
>> str = readln;
>> writeln(str);
>>
>> However, the prompt appears after I enter the input; any reason why?
>>
>> I've trawled the internet for a good hour, but I can't seem to find an answer.
>
> Your code is correct, it's your terminal or whatever you use to see your program's output that doesn't flush stdout. You can force it though:
>
> string str;
> writeln("Enter a string: ");
> stdout.flush;
> str = readln;
> write(str);
Thank you, again.
|
Copyright © 1999-2021 by the D Language Foundation