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.File.readf
Reads formatted data from the file using std
.
uint readf(alias format, Data...)
(
auto ref Data data
)
if (isSomeString!(typeof(format)));
uint readf(Data...)
(
scope const(char)[] format,
auto ref Data data
);
Parameters
Name | Description |
---|---|
format | The format string. When passed as a compile-time argument, the string will be statically checked against the argument types passed. |
data | 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;
auto f = File("input");
foreach (_; 0 .. 3)
{
int a;
f .readf!" %d"(a);
writeln(++a);
}
}
% echo "1 2 3" > input % rdmd test.d 2 3 4
Example
static import std .file;
auto deleteme = std .file .deleteme();
write(deleteme, "hello\nworld\ntrue\nfalse\n");
scope(exit) remove(deleteme);
string s;
auto f = File(deleteme);
f .readf!"%s\n"(s);
writeln(s); // "hello"
f .readf("%s\n", s);
writeln(s); // "world"
bool b1, b2;
f .readf("%s\n%s\n", b1, b2);
assert(b1 == true && b2 == false);
Authors
Walter Bright, Andrei Alexandrescu, Alex Rønne Petersen
License
Copyright © 1999-2024 by the D Language Foundation | Page generated by ddox.