Conversion string->int
Paul via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sat Jun 7 14:22:03 PDT 2014
On Saturday, 7 June 2014 at 21:15:37 UTC, monarch_dodra wrote:
> 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.
But to!string(s) creates temporary string object or I am not
right? And this temp string is pushed as argument of parse... Or
not?
More information about the Digitalmars-d-learn
mailing list