www.digitalmars.com

D Programming Language 1.0

Last update Fri Oct 5 00:37:21 2007

std.stdio

Standard I/O functions that extend std.c.stdio. std.c.stdio is automatically imported when importing std.stdio.

class StdioException: object.Exception;
Thrown if I/O errors happen.

void writef(...);
Arguments are formatted per the format strings and written to stdout.

void writefln(...);
Same as writef, but a newline is appended to the output.

void fwritef(_iobuf * fp,...);
Same as writef, but output is sent to the stream fp instead of stdout.

void fwritefln(_iobuf * fp,...);
Same as writefln, but output is sent to the stream fp instead of stdout.

char[] readln(_iobuf * fp = & _iob);
Read line from stream fp.

Returns:
null for end of file, char[] for line read from fp, including terminating '\n'

Params:
_iobuf * fp input stream

Throws:
StdioException on error

Example:
Reads stdin and writes it to stdout.
import std.stdio;

int main()
{
    char[] buf;
    while ((buf = readln()) != null)
	writef("%s", buf);
    return 0;
}


uint readln(_iobuf * fp, ref char[] buf);
uint readln(ref char[] buf);
Read line from stream fp and write it to buf[], including terminating '\n'.

This is often faster than readln(FILE*) because the buffer is reused each call. Note that reusing the buffer means that the previous contents of it need to be copied if needed.

Params:
_iobuf * fp input stream
char[] buf buffer used to store the resulting line data. buf is resized as necessary.

Returns:
0 for end of file, otherwise number of characters read

Throws:
StdioException on error

Example:
Reads stdin and writes it to stdout.
import std.stdio;

int main()
{
    char[] buf;
    while (readln(stdin, buf))
	writef("%s", buf);
    return 0;
}