val fprintf: out_channel -> ('a, out_channel, unit) format -> 'a
fprintf outchan format arg1 ... argN
formats the argumentsarg1
toargN
according to the format stringformat
, and outputs the resulting string on the channeloutchan
.
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 conversion character. The conversion characters and their meanings are:d
ori
: 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.s
: insert a string argumentc
: insert a character argumentf
: convert a floating-point argument to decimal notation, in the styledddd.ddd
e
orE
: convert a floating-point argument to decimal notation, in the styled.ddd e+-dd
(mantissa and exponent)g
orG
: convert a floating-point argument to decimal notation, in stylef
ore
,E
(whichever is more compact)b
: convert a boolean argument to the stringtrue
orfalse
a
: user-defined printer. Takes two arguments and apply the first one tooutchan
(the current output channel) and to the second argument. The first argument must therefore have typeout_channel -> 'b -> unit
and the second'b
. The output produced by the function is therefore inserted in the output offprintf
at the current point.t
: same as%a
, but takes only one argument (with typeout_channel -> unit
) and apply it tooutchan
.%
: take no argument and output one%
character.
Refer to the C libraryprintf
function for the meaning of flags and field width specifiers.
If too few arguments are provided, printing stops just before converting the first missing argument.
val printf: ('a, out_channel, unit) format -> 'a
Same asfprintf
, but output onstdout
.
val eprintf: ('a, out_channel, unit) format -> 'a
Same asfprintf
, but output onstderr
.
val sprintf: ('a, unit, string) format -> 'a
Same as 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 asfprintf
, but instead of printing on an output channel, append the formatted arguments to the given extensible buffer (see moduleBuffer
).