Search code examples
d

Reading an array of elements with readf in D


Is it possible to read an array (of given length) of elements using readf in D, without looping?

And is it possible if the length is not known?

I tried using the same syntax used for formatted writing, %(%d %), but it does not work.

EDIT: More generally, is readf capable of using the same formats for writef?


Solution

  • There is currently a bug (Bugzilla 10060) that prevents this from working, but it does work for linewise reading.

    foreach (line; stdin.byLine())
    {
        int[] result;
        formattedRead(line, "%(%d,%)", &result);
        writeln(result);
    }