%s not producing string representation of enum?
Daniel Kozak via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Thu Dec 10 06:37:05 PST 2015
V Thu, 10 Dec 2015 19:54:43 +0530
Shriramana Sharma via Digitalmars-d-learn
<digitalmars-d-learn at puremagic.com> napsáno:
> Hello. I'm using DMD 2.069.2. As per
> http://ddili.org/ders/d.en/enum.html the following code is supposed
> to output the *names* of the suits:
>
> import std.stdio;
> void main()
> {
> enum Suit { spades, hearts, diamonds, clubs }
> foreach (suit; Suit.min .. Suit.max + 1) { writefln("%s", suit); }
> }
>
> But I'm getting 0 1 2 3. Kindly advise.
>
void main() {
writeln(typeid(typeof(Suit.max)));
writeln(typeid(typeof(Suit.max + 1)));
}
+ 1 makes int from Suit
import std.stdio;
import std.conv;
foreach (suit; Suit.min .. Suit.max + 1)
{
enum Suit { spades, hearts, diamonds, clubs }
writefln("%s", to!Suit(suit));
}
More information about the Digitalmars-d-learn
mailing list