Am 13.01.2012 22:16, Piotr Szturmaj wrote:
Jorge wrote:
My first question si very silly:

string str = readln()

my input is for example 123

how can i convert this to an integer?

import std.conv;

// then in code:

auto i = to!int(str);

the string returned by readln() ends with NL ('\n'), which causes std.conv.to to raise an ConvException. You also must slice it away:

auto i = to!int(str[0..$-1]);

or you use std.conv.parse, which ignores the characters after the value and removes the converted characters from the string.

Reply via email to