Conversion string->int

anonymous via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Jun 7 14:19:20 PDT 2014


On Saturday, 7 June 2014 at 20:53:03 UTC, Paul wrote:
> I can not understand, why this code works:
>
>     char s[2] = ['0', 'A'];
>     string ss = to!string(s);
>     writeln(parse!uint(ss, 16));
>
> but this can deduces template:
>
>     char s[2] = ['0', 'A'];
>     writeln(parse!uint(to!string(s), 16));
>
> What's the reason?

`parse` takes its argument by ref. It pops the characters it
reads from the source. So in your first snippet, ss will be empty
when parse is done with it.

> And what is the right way to parse char[2]->int with radix?

In this case you can use to!uint(foo, 16) instead.


More information about the Digitalmars-d-learn mailing list