std.string.format uses std.format.doFormat, and it is based on RTTI. On the other hand, writeln/writefln uses std.format.formattedWrite and formatValue, they are based on Compile Time Reflection. So the results are different.
In 2.060head, std.string.xformat is added, and it works as like writefln. https://github.com/D-Programming-Language/phobos/blob/master/std/string.d#L2611 Bye. Kenji Hara 2012/7/1 d coder <[email protected]>: > Greetings > > std.string.format throws runtime exception for BigInt and for BitArray types > even though writefln works fine. The run-time error says > std.format.FormatException@std/format.d(4744): Can't convert > std.bigint.BigInt to string: "string toString()" not defined > > Here is a small test case. > > Regards > - Puneet > > void main() > { > import std.stdio; > import std.string; > import std.bigint; > import std.bitmanip; > > BigInt aa = 100; > > BitArray bb; > bb.init([true, false]); > > writefln("%x", aa); > writefln("%x", bb); > writeln(format("%x", aa)); > writeln(format("%x", bb)); > } >
