Conversion string->int

monarch_dodra via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Jun 7 14:15:35 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? And what is the right way to parse 
> char[2]->int with radix?

parse takes an lvalue to a range. char[2] is a static array, and 
is not a range. You need to store an actual "char[]" (or string) 
in a variable to call parse. So "ss" will work, "to!string(s)" 
will not.


More information about the Digitalmars-d-learn mailing list