Does D have something like Java Scanner?

Is there a flow analyzer in D, for example, a Java scanner? If you can just go nextInt()to get intand nextLong()for longetc.

+4
source share
1 answer

std.conv.parse is similar: http://dlang.org/phobos/std_conv.html#parse

An example is a string, although it can also be used with other character sources.

import std.conv;
import std.stdio;

void main() {
    // a char source from the user
    auto source = LockingTextReader(stdin);

    int a = parse!int(source); // use it with parse
    writeln("you wrote ", a);

    // munch only works on actual strings so we have to advance
    // this manually
    for(; !source.empty; source.popFront()) {
        auto ch = source.front;
        if(ch != ' ' && ch != '\n')
            break;
    }
    int b = parse!int(source);
    writeln("then you wrote ", b);
}

$. / test56 12 23 you wrote 12 then you wrote 23

+6
source

Source: https://habr.com/ru/post/1532202/


All Articles