readf with strings

Kai Meyer kai at unixlords.com
Thu Jun 23 09:35:57 PDT 2011


On 06/23/2011 02:27 AM, Dainius (GreatEmerald) wrote:
>> I have a related enhancement request since lot of time:
>> http://d.puremagic.com/issues/show_bug.cgi?id=4716
>>
>> Bye,
>> bearophile
>>
>
> That's exactly what I'd like to see. Voted.
>
> After all, D is created with practicality in mind, and doing all that
> parsing is the opposite of what it's trying to achieve.

The goal here is to have semantics for "Read an int from STDIN." I think 
the difficulty here is this really *should* be "Read a T from a stream." 
In C++, we have the stream operators ">>" and "<<". I really really 
really really miss these. I would love to have my stream operators back 
(and then implement the operators for classes and structs.) I think that 
"a = stdin.type_read!int();" or "std.type_read!int(&a);" would go a long 
way in getting there, as long as we could extend the template. I don't 
like the way python takes input from STDIN with raw_input() and input(). 
I'm not opposed to having a language support those semantics, but I 
would rather have a generic stream reader that does the conversion to a 
type for me that allows me to extend the conversion to include my own types.


More information about the Digitalmars-d-learn mailing list