std.stdio

Standard I/O functions that extend core.stdc.stdio. core.stdc.stdio is publically imported when importing std.stdio.

Public Imports

core.stdc.stdio
public import core.stdc.stdio;

Members

Aliases

KeepTerminator
alias KeepTerminator = Flag!"keepTerminator"

If flag KeepTerminator is set to KeepTerminator.yes, then the delimiter is included in the strings returned.

stderr
alias stderr = makeGlobal!(StdFileHandle.stderr)

The standard error stream.

stdin
alias stdin = makeGlobal!(StdFileHandle.stdin)

The standard input stream.

stdout
alias stdout = makeGlobal!(StdFileHandle.stdout)

The standard output stream.

Classes

StdioException
class StdioException

Thrown if I/O errors happen.

Enums

LockType
enum LockType

Used to specify the lock type for File.lock and File.tryLock.

Functions

_popen
FILE* _popen(R1 name, R2 mode)

Convenience function that forwards to core.sys.posix.stdio.popen with appropriately-constructed C-style strings.

chunks
auto chunks(File f, size_t size)

Iterates through a file a chunk at a time by using foreach.

openNetwork
File openNetwork(string host, ushort port)

Experimental network access via the File interface

readf
uint readf(A args)
uint readf(const(char)[] format, A args)

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

readln
S readln(dchar terminator)

* Read line from stdin. * * This version manages its own read buffer, which means one memory allocation per call. If you are not * retaining a reference to the read data, consider the readln(buf) version, which may offer * better performance as it can reuse its read buffer. * * Returns: * The line that was read, including the line terminator character. * Params: * S = Template parameter; the type of the allocated buffer, and the type returned. Defaults to string. * terminator = Line terminator (by default, '\n'). * Note: * String terminators are not supported due to ambiguity with readln(buf) below. * Throws: * StdioException on I/O error, or UnicodeException on Unicode conversion error. * Example: * Reads stdin and writes it to stdout.

readln
size_t readln(C[] buf, dchar terminator)
size_t readln(C[] buf, R terminator)

* Read line from stdin and write it to buf[], including terminating character. * * This can be faster than line = readln() because you can reuse * the buffer for each call. Note that reusing the buffer means that you * must copy the previous contents if you wish to retain them. * * Returns: * size_t 0 for end of file, otherwise number of characters read * Params: * buf = Buffer used to store the resulting line data. buf is resized as necessary. * terminator = Line terminator (by default, '\n'). Use std.ascii.newline * for portability (unless the file was opened in text mode). * Throws: * StdioException on I/O error, or UnicodeException on Unicode conversion error. * Example: * Reads stdin and writes it to stdout.

toFile
void toFile(T data, string fileName)

Writes an array or range to a file. Shorthand for data.copy(File(fileName, "wb").lockingBinaryWriter). Similar to std.file.write, strings are written as-is, rather than encoded according to the File's orientation.

write
void write(T args)

Writes its arguments in text format to standard output (without a trailing newline).

writef
void writef(A args)
void writef(Char[] fmt, A args)

Writes formatted data to standard output (without a trailing newline).

writefln
void writefln(A args)
void writefln(Char[] fmt, A args)

Equivalent to writef(fmt, args, '\n').

writeln
void writeln(T args)

Equivalent to write(args, '\n'). Calling writeln without arguments is valid and just prints a newline to the standard output.

Structs

File
struct File

Encapsulates a FILE*. Generally D does not attempt to provide thin wrappers over equivalent functions in the C standard library, but manipulating FILE* values directly is unsafe and error-prone in many ways. The File type ensures safe manipulation, automatic file closing, and a lot of convenience.

lines
struct lines

Iterates through the lines of a file by using foreach.

Templates

isFileHandle
template isFileHandle(T)

Indicates whether T is a file handle, i.e. the type is implicitly convertable to File or a pointer to a core.stdc.stdio.FILE.

Meta