D有像Java的扫描仪吗?

dsp*_*pyz 4 d java.util.scanner

像Java的扫描仪那样在D中是否有流解析器?在哪里你可以nextInt()去取一个intnextLong()一个long等等.

Ada*_*ppe 6

std.conv.parse类似:http://dlang.org/phobos/std_conv.html#parse

该示例是一个字符串,但也可以将其与其他字符源一起使用.

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);
}
Run Code Online (Sandbox Code Playgroud)

$ ./test56 12 23你写了12然后你写了23