stdio line-streaming revisited
kris
foo at bar.com
Thu Mar 29 10:24:13 PDT 2007
Andrei Alexandrescu (See Website For Email) wrote:
> kris wrote:
>
>> Sean Kelly wrote:
>> [snip]
>>
>>> I must be missing something. Why is the following not acceptable?
>>>
>>> import tango.io.Console;
>>>
>>> void main()
>>> {
>>> char[] name;
>>> Cout( "Please enter your name: " ).flush;
>>> Cin.nextLine( name );
>>> Cout( "Hello, " )( name )( "!" );
>>> }
>>
>>
>>
>> There used to be a tango/example like this variation:
>>
>> import tango.io.Console;
>>
>> void main()
>> {
>> Cout ("Please enter your name: ").flush;
>> Cout ("Hello, ") (Cin.get);
>> }
>
>
> Ah, also, the last line is translated into:
>
> Cout.opCall("Hello, ").opCall(Cin.get);
>
> D does not specify evaluation order, so the code might end up printing
> "Hello, " before reading the standard input. It's funny this does not
> happen exactly because of buffering, but the program has no control over
> the buffering so it should assume flushing could happen at any time. So
> the correct code is:
>
> auto name = Cin.get;
> Cout("Hello, ")(name);
Well aware of that, thanks. BTW: evaluation order has been clarified
before, on a similar topic.
More information about the Digitalmars-d
mailing list