How to read from an input stream generically?
Ali Çehreli
acehreli at yahoo.com
Wed Feb 24 18:40:10 PST 2010
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
More information about the Digitalmars-d-learn
mailing list