Why I could not cast string to int?

Alex Rønne Petersen xtzgzorex at gmail.com
Thu Feb 2 10:10:56 PST 2012


On 02-02-2012 17:26, xancorreu wrote:
> Why cast(int) does not work and I have to call another function?
>
> Thanks,
>
> Al 02/02/12 17:24, En/na Adam D. Ruppe ha escrit:
>> On Thursday, 2 February 2012 at 16:21:39 UTC, xancorreu wrote:
>>> $ ./factorial 222
>>> Factorial requires a number
>>
>> args[0] is the name of your program.
>> (The first thing you typed on the command
>> line.)
>>
>> Use args[1] to get that number.
>>
>>> parse() where is the doc?
>>
>> http://www.d-programming-language.org/phobos/std_conv.html#parse
>>
>>
>> to!int(args[1]) is probably what you want here though.
>

Because D is a strongly typed language. Casting a string to an int 
doesn't make sense from a type system perspective.

--
- Alex


More information about the Digitalmars-d-learn mailing list