User input

Ali Çehreli acehreli at yahoo.com
Wed Nov 8 17:46:43 UTC 2017


On 11/08/2017 09:19 AM, Namal wrote:
> Is there any other way to do a simple user input into integer variables 
> without using std.conv?

import std.stdio;

void main() {
     int i;
     readf(" %s", &i);    // You can use %d as well

     // You can wrap readf in a function template for a more natural use:
     int j = read!int();
}

T read(T)()
{
     T value;
     readf(" %s", &value);
     return value;
}

Ali


More information about the Digitalmars-d-learn mailing list