View source code Display the source code in std/file.d from which this page was generated on github. 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. Page wiki View or edit the community-maintained wiki page associated with this page.

Function std.file.slurp

Reads an entire file into an array.

Prototype

Select!(Types.length==1,Types[0][],Tuple!Types[]) slurp(Types...)(
  string filename,
  char[] format
);

Example

// Load file; each line is an int followed by comma, whitespace and a
// double.
auto a = slurp!(int, double)("filename", "%s, %s");

Bugs

slurp expects file names to be encoded in CP_ACP on Windows instead of UTF-8 (as it internally uses std.stdio.File, see Bugzilla 7648) thus must not be used in Windows or cross-platform applications other than with an immediate ASCII string as a file name to prevent accidental changes to result in incorrect behavior.

Authors

Walter Bright, Andrei Alexandrescu, Jonathan M Davis

License

Boost License 1.0.

Comments