Skip to content
Variables and I/O
step 1/5

Reading — step 1 of 5

Learn

~1 min readBasics

D is statically typed but supports rich inference:

int age = 36;
string name = "Ada";
double pi = 3.14159;
bool active = true;

auto inferred = 42;     // int
auto greeting = "hi";   // string

Numeric types: byte, short, int, long (signed), ubyteulong (unsigned), float, double, real (extended precision).

Reading typed input from stdin uses readf:

import std.stdio;
int a, b;
readf("%d %d", &a, &b);
writeln(a + b);

For reading line-by-line and parsing yourself:

import std.conv : to;
import std.string : chomp;
int n = readln().chomp.to!int;

to!Type is D's templated conversion — clean and type-safe.

Discussion

Ask a question, share an insight, or help someone who’s stuck.

Sign in to post a comment or reply.

Loading…