Scanner

Scanner 速くはないが遅くもない printf/scanfよりちょっと遅いくらい?

Constructors

this
this(File f)
Undocumented in source.

Members

Functions

read
int read(T x, Args args)
Undocumented in source. Be warned that the author may not have intended to support it.

Variables

f
File f;
Undocumented in source.
line
char[] line;
Undocumented in source.
lineBuf
char[512] lineBuf;
Undocumented in source.

Examples

import std.path : buildPath;
import std.file : tempDir;
import std.algorithm : equal;
import std.stdio : File;
string fileName = buildPath(tempDir, "kyuridenanmaida.txt");
auto fout = File(fileName, "w");
fout.writeln("1 2 3");
fout.writeln("ab cde");
fout.writeln("1.0 1.0 2.0");
fout.close;
Scanner sc = new Scanner(File(fileName, "r"));
int a;
int[2] b;
char[2] c;
string d;
double e;
double[] f;
sc.read(a, b, c, d, e, f);
assert(a == 1);
assert(equal(b[], [2, 3])); // 配列型は行末まで読み込む
assert(equal(c[], "ab")); // char型配列はトークンをそのまま返す
assert(equal(d, "cde")); // stringもchar型配列と同様
assert(e == 1.0); // 小数も可
assert(equal(f, [1.0, 2.0]));
assert(sc.read(a) == 0); // EOF

Meta