About to!int

Zardoz luis.panadero at gmail.com
Mon Jan 30 23:33:54 PST 2012


On Mon, 30 Jan 2012 21:01:38 -0500, bearophile wrote:


> 
> In D  to!int(" 12\n")  gives a run-time error. So time ago I have weakly
> asked Andrei to change to!int, to let it ignore leading and trailing
> whitespace, but he has ignored my request.
> 
> A leading newline comes often from input stdin.readln() and other
> sources. So in D you need to add a strip():
> 
> int n = to!int(stdin.readln().strip());
> 
> Bye,
> bearophile

Try parse!int(" 12\n");
http://www.d-programming-language.org/phobos/std_conv.html#parse


-- 
Yep, I'm afraid that I have a blog : zardoz.es


More information about the Digitalmars-d-learn mailing list