On 01/13/2012 10:34 PM, Jorge wrote:
Thanks for your answer but:

import std.stdio;
import std.conv;
void main()
{
        write("Insert number: ");
        string s = readln();
        auto i = to!int(s);
}

compiles but after i enter a number and press the enter key i get:

std.conv.ConvException@.\..\..\src\phobos\std\conv.d(1595): Can't
convert value
`
' of type string to type int
----------------
41DECC
41DD43
4027F3
402475
402D6C
402DB0
4029A7
4BBA79
----------------

what's wrong?

readln() includes the trailing newline character in the resulting string. You can use std.string.strip to remove leading and trailing whitespace:

import std.stdio;
import std.conv;
import std.string;
void main()
{
    write("Insert number: ");
    string s = readln();
    auto i = to!int(strip(s));
}

Reply via email to