digitalmars.D.learn - How to read from an input stream generically?
- =?UTF-8?B?QWxpIMOHZWhyZWxp?= (21/21) Feb 24 2010 What can I use instead of the din.readf line below to be able to read
What can I use instead of the din.readf line below to be able to read
any type in that generic function?
import std.cstream;
struct MyType
{}
void generic(T)()
{
T var;
dout.writef("Please enter a value of type %s: ", T.stringof);
din.readf(&var); // <-- Runtime ERROR for MyType
}
void main()
{
generic!int();
generic!MyType();
}
I am looking for a substitute for C++'s operator>> overloads for user
types. I could of course implement a static read(Stream) function for my
types, but not for the fundamental types.
Thank you,
Ali
Feb 24 2010








=?UTF-8?B?QWxpIMOHZWhyZWxp?= <acehreli yahoo.com>