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.byRecord

Creates an input range set up to parse one line at a time from the file into a tuple.

auto byRecord(Fields...) (
  string format
);

Range primitives may throw StdioException on I/O error.

Parameters

NameDescription
format tuple record format

Returns

The input range set up to parse one line at a time into a record tuple.

See Also

It is similar to byLine and uses format under the hood.

Example

static import std.file;
import std.typecons : tuple;

// prepare test file
auto testFile = std.file.deleteme();
scope(failure) printf("Failed test at line %d\n", __LINE__);
write(testFile, "1 2\n4 1\n5 100");
scope(exit) remove(testFile);

File f = File(testFile);
scope(exit) f.close();

auto expected = [tuple(1, 2), tuple(4, 1), tuple(5, 100)];
uint i;
foreach (e; f.byRecord!(int, int)("%s %s"))
{
    writeln(e); // expected[i++]
}

Authors

Walter Bright, Andrei Alexandrescu, Alex Rønne Petersen

License

Boost License 1.0.