Module Printf


module Printf: sig .. end
Formatted output functions.

val fprintf : out_channel ->
('a, out_channel, unit) format -> 'a
fprintf outchan format arg1 ... argN formats the arguments arg1 to argN according to the format string format, and outputs the resulting string on the channel outchan.

The format is a character string which contains two types of objects: plain characters, which are simply copied to the output channel, and conversion specifications, each of which causes conversion and printing of one argument.

Conversion specifications consist in the % character, followed by optional flags and field widths, followed by one or two conversion character. The conversion characters and their meanings are:

The optional flags include: The field widths are composed of an optional integer literal indicating the minimal width of the result, possibly followed by a dot . and another integer literal indicating how many digits follow the decimal point in the %f, %e, and %E conversions. For instance, %6d prints an integer, prefixing it with spaces to fill at least 6 characters; and %.4f prints a float with 4 fractional digits. Each or both of the integer literals can also be specified as a *, in which case an extra integer argument is taken to specify the corresponding width or precision.

Warning: if too few arguments are provided, for instance because the printf function is partially applied, the format is immediately printed up to the conversion of the first missing argument; printing will then resume when the missing arguments are provided. For example, List.iter (printf "x=%d y=%d " 1) [2;3] prints x=1 y=2 3 instead of the expected x=1 y=2 x=1 y=3. To get the expected behavior, do List.iter (fun y -> printf "x=%d y=%d " 1 y) [2;3].

val printf : ('a, out_channel, unit) format -> 'a
Same as Printf.fprintf, but output on stdout.
val eprintf : ('a, out_channel, unit) format -> 'a
Same as Printf.fprintf, but output on stderr.
val sprintf : ('a, unit, string) format -> 'a
Same as Printf.fprintf, but instead of printing on an output channel, return a string containing the result of formatting the arguments.
val bprintf : Buffer.t -> ('a, Buffer.t, unit) format -> 'a
Same as Printf.fprintf, but instead of printing on an output channel, append the formatted arguments to the given extensible buffer (see module Buffer).
val kprintf : (string -> 'a) -> ('b, unit, string, 'a) format4 -> 'b
kprintf k format arguments is the same as sprintf format arguments, except that the resulting string is passed as argument to k; the result of k is then returned as the result of kprintf.