module Printf = struct ... end
Functions |
fprintf
: Pervasives.out_channel -> ('c, Pervasives.out_channel, unit) format -> 'c |
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
.%
character, followed
by optional flags and field widths, followed by one conversion
character. The conversion characters and their meanings are:d
or i
: convert an integer argument to signed decimalu
: convert an integer argument to unsigned decimalx
: convert an integer argument to unsigned hexadecimal,
using lowercase letters.X
: convert an integer argument to unsigned hexadecimal,
using uppercase letters.o
: convert an integer argument to unsigned octal.s
: insert a string argumentc
: insert a character argumentf
: convert a floating-point argument to decimal notation,
in the style dddd.ddd
e
or E
: convert a floating-point argument to decimal notation,
in the style d.ddd e+-dd
(mantissa and exponent)g
or G
: convert a floating-point argument to decimal notation,
in style f
or e
, E
(whichever is more compact)b
: convert a boolean argument to the string true
or false
a
: user-defined printer. Takes two arguments and apply the first
one to outchan
(the current output channel) and to the second
argument. The first argument must therefore have type
out_channel -> 'b -> unit
and the second 'b
.
The output produced by the function is therefore inserted
in the output of fprintf
at the current point.t
: same as %a
, but takes only one argument (with type
out_channel -> unit
) and apply it to outchan
.%
: take no argument and output one %
character.printf
function for the meaning of
flags and field width specifiers.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]
.
printf
: ('d, Pervasives.out_channel, unit) format -> 'd |
fprintf
, but output on stdout
.
eprintf
: ('e, Pervasives.out_channel, unit) format -> 'e |
fprintf
, but output on stderr
.
sprintf
: ('f, unit, string) format -> 'f |
fprintf
, but instead of printing on an output channel,
return a string containing the result of formatting
the arguments.
bprintf
: Buffer.t -> ('g, Buffer.t, unit) format -> 'g |
fprintf
, but instead of printing on an output channel,
append the formatted arguments to the given extensible buffer
(see module Buffer
).