overloading operators for I/O

renoX renosky at free.fr
Thu Feb 15 14:06:04 PST 2007


Don Clugston a écrit :
> I agree. There's another problem -- it(<<) really doesn't scale well. With 
> printf, you can do "%3.5f" to print a floating point number with a given 
> precision. With <<, that same operation is really horrible.

Agreed, and writef is even better:
writef("x is %d",vx," y is %g\n",vy);

No need to put the format string on one side and variables on the other 
side..

It has still deficiencies:
- a syntax 'a la Ruby' would permit to see better the resulting string:
writef("x is %{vx}, y is %{vy}\n"); of course you could still specify 
the format if you want: writef("x is %08x{vx}\n");

- why writef doesn't call to_String on struct or on a type?
I.e:
typedef int foo;

char[] toString(foo x)
{
	return "foo";
}

doesn't work as expected in a writef, same with a struct defining a 
toString function..

renoX



More information about the Digitalmars-d mailing list