View source code
Display the source code in std/stdio.d from which this page was generated on github.
Report a bug
If you spot a problem with this page, click here to create a Bugzilla issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page. Requires a signed-in GitHub account. This works well for small changes. If you'd like to make larger changes you may want to consider using local clone.

Function std.stdio.readf

Reads formatted data from stdin using std.format.formattedRead.

uint readf(alias format, A...) (
  auto ref A args
)
if (isSomeString!(typeof(format)));

uint readf(A...) (
  scope const(char)[] format,
  auto ref A args
);

Parameters

NameDescription
format The format string. When passed as a compile-time argument, the string will be statically checked against the argument types passed.
args Items to be read.

Returns

Same as formattedRead: The number of variables filled. If the input range r ends early, this number will be less than the number of variables provided.

Example

// test.d
void main()
{
    import std.stdio;
    foreach (_; 0 .. 3)
    {
        int a;
        readf!" %d"(a);
        writeln(++a);
    }
}

% echo "1 2 3" | rdmd test.d
2
3
4

Authors

Walter Bright, Andrei Alexandrescu, Alex Rønne Petersen

License

Boost License 1.0.