www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - std.string.format results in run-time exception

--e0cb4efe2a289ecc0504c3b46eb8
Content-Type: text/plain; charset=ISO-8859-1

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));
}

--e0cb4efe2a289ecc0504c3b46eb8
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

<div>Greetings</div><div><br></div><div>std.string.format throws runtime ex=
ception for BigInt and for BitArray types even though writefln works fine. =
The run-time error says=A0</div><div>std.format.FormatException std/format.=
d(4744): Can&#39;t convert std.bigint.BigInt to string: &quot;string toStri=
ng()&quot; not defined</div>

<div><br></div><div>Here is a small test case.</div><div><br></div><div>Reg=
ards</div><div>- Puneet</div><div><br></div><div>void main()</div><div>{</d=
iv><div>=A0 import std.stdio;</div><div>=A0 import std.string;</div><div>=
=A0 import std.bigint;</div>

<div>=A0 import std.bitmanip;</div><div><br></div><div>=A0 BigInt aa =3D 10=
0;</div><div><br></div><div>=A0 BitArray bb;</div><div>=A0 bb.init([true, f=
alse]);</div><div><br></div><div>=A0 writefln(&quot;%x&quot;, aa);</div><di=
v>=A0 writefln(&quot;%x&quot;, bb);</div>

<div>=A0 writeln(format(&quot;%x&quot;, aa));</div><div>=A0 writeln(format(=
&quot;%x&quot;, bb));</div><div>}</div><div><br></div>

--e0cb4efe2a289ecc0504c3b46eb8--
Jun 30 2012