766 lines
9.4 KiB
HTML
766 lines
9.4 KiB
HTML
|
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
<HTML><HEAD><TITLE>Man page of Stdlib.Printf</TITLE>
|
|
</HEAD><BODY>
|
|
<H1>Stdlib.Printf</H1>
|
|
Section: OCaml library (3o)<BR>Updated: 2020-01-30<BR><A HREF="#index">Index</A>
|
|
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
|
|
|
|
<A NAME="lbAB"> </A>
|
|
<H2>NAME</H2>
|
|
|
|
Stdlib.Printf - no description
|
|
<A NAME="lbAC"> </A>
|
|
<H2>Module</H2>
|
|
|
|
Module Stdlib.Printf
|
|
<A NAME="lbAD"> </A>
|
|
<H2>Documentation</H2>
|
|
|
|
<P>
|
|
Module
|
|
<B>Printf</B>
|
|
|
|
<BR> :
|
|
<B>(module Stdlib__printf)</B>
|
|
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val fprintf </I>
|
|
|
|
:
|
|
<B>out_channel -> ('a, out_channel, unit) format -> 'a</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>fprintf outchan format arg1 ... argN</B>
|
|
|
|
formats the arguments
|
|
<B>arg1</B>
|
|
|
|
to
|
|
<B>argN</B>
|
|
|
|
according to the format string
|
|
<B>format</B>
|
|
|
|
, and
|
|
outputs the resulting string on the channel
|
|
<B>outchan</B>
|
|
|
|
.
|
|
<P>
|
|
The format string 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 arguments.
|
|
<P>
|
|
Conversion specifications have the following form:
|
|
<P>
|
|
<P>
|
|
<B>% [flags] [width] [.precision] type</B>
|
|
|
|
<P>
|
|
In short, a conversion specification consists in the
|
|
<B>%</B>
|
|
|
|
character,
|
|
followed by optional modifiers and a type which is made of one or
|
|
two characters.
|
|
<P>
|
|
The types and their meanings are:
|
|
<P>
|
|
<P>
|
|
-
|
|
<B>d</B>
|
|
|
|
,
|
|
<B>i</B>
|
|
|
|
: convert an integer argument to signed decimal.
|
|
<P>
|
|
-
|
|
<B>u</B>
|
|
|
|
,
|
|
<B>n</B>
|
|
|
|
,
|
|
<B>l</B>
|
|
|
|
,
|
|
<B>L</B>
|
|
|
|
, or
|
|
<B>N</B>
|
|
|
|
: convert an integer argument to
|
|
unsigned decimal. Warning:
|
|
<B>n</B>
|
|
|
|
,
|
|
<B>l</B>
|
|
|
|
,
|
|
<B>L</B>
|
|
|
|
, and
|
|
<B>N</B>
|
|
|
|
are
|
|
used for
|
|
<B>scanf</B>
|
|
|
|
, and should not be used for
|
|
<B>printf</B>
|
|
|
|
.
|
|
<P>
|
|
-
|
|
<B>x</B>
|
|
|
|
: convert an integer argument to unsigned hexadecimal,
|
|
using lowercase letters.
|
|
<P>
|
|
-
|
|
<B>X</B>
|
|
|
|
: convert an integer argument to unsigned hexadecimal,
|
|
using uppercase letters.
|
|
<P>
|
|
-
|
|
<B>o</B>
|
|
|
|
: convert an integer argument to unsigned octal.
|
|
<P>
|
|
-
|
|
<B>s</B>
|
|
|
|
: insert a string argument.
|
|
<P>
|
|
-
|
|
<B>S</B>
|
|
|
|
: convert a string argument to OCaml syntax (double quotes, escapes).
|
|
<P>
|
|
-
|
|
<B>c</B>
|
|
|
|
: insert a character argument.
|
|
<P>
|
|
-
|
|
<B>C</B>
|
|
|
|
: convert a character argument to OCaml syntax
|
|
(single quotes, escapes).
|
|
<P>
|
|
-
|
|
<B>f</B>
|
|
|
|
: convert a floating-point argument to decimal notation,
|
|
in the style
|
|
<B>dddd.ddd</B>
|
|
|
|
.
|
|
<P>
|
|
-
|
|
<B>F</B>
|
|
|
|
: convert a floating-point argument to OCaml syntax (
|
|
<B>dddd.</B>
|
|
|
|
or
|
|
<B>dddd.ddd</B>
|
|
|
|
or
|
|
<B>d.ddd e+-dd</B>
|
|
|
|
).
|
|
<P>
|
|
-
|
|
<B>e</B>
|
|
|
|
or
|
|
<B>E</B>
|
|
|
|
: convert a floating-point argument to decimal notation,
|
|
in the style
|
|
<B>d.ddd e+-dd</B>
|
|
|
|
(mantissa and exponent).
|
|
<P>
|
|
-
|
|
<B>g</B>
|
|
|
|
or
|
|
<B>G</B>
|
|
|
|
: convert a floating-point argument to decimal notation,
|
|
in style
|
|
<B>f</B>
|
|
|
|
or
|
|
<B>e</B>
|
|
|
|
,
|
|
<B>E</B>
|
|
|
|
(whichever is more compact). Moreover,
|
|
any trailing zeros are removed from the fractional part of the result
|
|
and the decimal-point character is removed if there is no fractional
|
|
part remaining.
|
|
<P>
|
|
-
|
|
<B>h</B>
|
|
|
|
or
|
|
<B>H</B>
|
|
|
|
: convert a floating-point argument to hexadecimal notation,
|
|
in the style
|
|
<B>0xh.hhhh e+-dd</B>
|
|
|
|
(hexadecimal mantissa, exponent in
|
|
decimal and denotes a power of 2).
|
|
<P>
|
|
-
|
|
<B>B</B>
|
|
|
|
: convert a boolean argument to the string
|
|
<B>true</B>
|
|
|
|
or
|
|
<B>false</B>
|
|
|
|
<P>
|
|
<P>
|
|
-
|
|
<B>b</B>
|
|
|
|
: convert a boolean argument (deprecated; do not use in new
|
|
programs).
|
|
<P>
|
|
-
|
|
<B>ld</B>
|
|
|
|
,
|
|
<B>li</B>
|
|
|
|
,
|
|
<B>lu</B>
|
|
|
|
,
|
|
<B>lx</B>
|
|
|
|
,
|
|
<B>lX</B>
|
|
|
|
,
|
|
<B>lo</B>
|
|
|
|
: convert an
|
|
<B>int32</B>
|
|
|
|
argument to
|
|
the format specified by the second letter (decimal, hexadecimal, etc).
|
|
<P>
|
|
-
|
|
<B>nd</B>
|
|
|
|
,
|
|
<B>ni</B>
|
|
|
|
,
|
|
<B>nu</B>
|
|
|
|
,
|
|
<B>nx</B>
|
|
|
|
,
|
|
<B>nX</B>
|
|
|
|
,
|
|
<B>no</B>
|
|
|
|
: convert a
|
|
<B>nativeint</B>
|
|
|
|
argument to
|
|
the format specified by the second letter.
|
|
<P>
|
|
-
|
|
<B>Ld</B>
|
|
|
|
,
|
|
<B>Li</B>
|
|
|
|
,
|
|
<B>Lu</B>
|
|
|
|
,
|
|
<B>Lx</B>
|
|
|
|
,
|
|
<B>LX</B>
|
|
|
|
,
|
|
<B>Lo</B>
|
|
|
|
: convert an
|
|
<B>int64</B>
|
|
|
|
argument to
|
|
the format specified by the second letter.
|
|
<P>
|
|
-
|
|
<B>a</B>
|
|
|
|
: user-defined printer. Take two arguments and apply the
|
|
first one to
|
|
<B>outchan</B>
|
|
|
|
(the current output channel) and to the
|
|
second argument. The first argument must therefore have type
|
|
<B>out_channel -> 'b -> unit</B>
|
|
|
|
and the second
|
|
<B>'b</B>
|
|
|
|
.
|
|
The output produced by the function is inserted in the output of
|
|
<B>fprintf</B>
|
|
|
|
at the current point.
|
|
<P>
|
|
-
|
|
<B>t</B>
|
|
|
|
: same as
|
|
<B>%a</B>
|
|
|
|
, but take only one argument (with type
|
|
<B>out_channel -> unit</B>
|
|
|
|
) and apply it to
|
|
<B>outchan</B>
|
|
|
|
.
|
|
<P>
|
|
-
|
|
<B>{ fmt %}</B>
|
|
|
|
: convert a format string argument to its type digest.
|
|
The argument must have the same type as the internal format string
|
|
<B>fmt</B>
|
|
|
|
.
|
|
<P>
|
|
-
|
|
<B>( fmt %)</B>
|
|
|
|
: format string substitution. Take a format string
|
|
argument and substitute it to the internal format string
|
|
<B>fmt</B>
|
|
|
|
to print following arguments. The argument must have the same
|
|
type as the internal format string
|
|
<B>fmt</B>
|
|
|
|
.
|
|
<P>
|
|
-
|
|
<B>!</B>
|
|
|
|
: take no argument and flush the output.
|
|
<P>
|
|
-
|
|
<B>%</B>
|
|
|
|
: take no argument and output one
|
|
<B>%</B>
|
|
|
|
character.
|
|
<P>
|
|
-
|
|
<B>@</B>
|
|
|
|
: take no argument and output one
|
|
<B>@</B>
|
|
|
|
character.
|
|
<P>
|
|
-
|
|
<B>,</B>
|
|
|
|
: take no argument and output nothing: a no-op delimiter for
|
|
conversion specifications.
|
|
<P>
|
|
The optional
|
|
<B>flags</B>
|
|
|
|
are:
|
|
<P>
|
|
-
|
|
<B>-</B>
|
|
|
|
: left-justify the output (default is right justification).
|
|
<P>
|
|
-
|
|
<B>0</B>
|
|
|
|
: for numerical conversions, pad with zeroes instead of spaces.
|
|
<P>
|
|
-
|
|
<B>+</B>
|
|
|
|
: for signed numerical conversions, prefix number with a
|
|
<B>+</B>
|
|
|
|
sign if positive.
|
|
<P>
|
|
-space: for signed numerical conversions, prefix number with a
|
|
space if positive.
|
|
<P>
|
|
-
|
|
<B>#</B>
|
|
|
|
: request an alternate formatting style for the integer types
|
|
(
|
|
<B>x</B>
|
|
|
|
,
|
|
<B>X</B>
|
|
|
|
,
|
|
<B>o</B>
|
|
|
|
,
|
|
<B>lx</B>
|
|
|
|
,
|
|
<B>lX</B>
|
|
|
|
,
|
|
<B>lo</B>
|
|
|
|
,
|
|
<B>Lx</B>
|
|
|
|
,
|
|
<B>LX</B>
|
|
|
|
,
|
|
<B>Lo</B>
|
|
|
|
,
|
|
<B>d</B>
|
|
|
|
,
|
|
<B>i</B>
|
|
|
|
,
|
|
<B>u</B>
|
|
|
|
,
|
|
<B>ld</B>
|
|
|
|
,
|
|
<B>li</B>
|
|
|
|
,
|
|
<B>lu</B>
|
|
|
|
,
|
|
<B>Ld</B>
|
|
|
|
,
|
|
<B>Li</B>
|
|
|
|
,
|
|
<B>Lu</B>
|
|
|
|
,
|
|
<B>nd</B>
|
|
|
|
,
|
|
<B>ni</B>
|
|
|
|
,
|
|
<B>nu</B>
|
|
|
|
).
|
|
<P>
|
|
The optional
|
|
<B>width</B>
|
|
|
|
is an integer indicating the minimal
|
|
width of the result. For instance,
|
|
<B>%6d</B>
|
|
|
|
prints an integer,
|
|
prefixing it with spaces to fill at least 6 characters.
|
|
<P>
|
|
The optional
|
|
<B>precision</B>
|
|
|
|
is a dot
|
|
<B>.</B>
|
|
|
|
followed by an integer
|
|
indicating how many digits follow the decimal point in the
|
|
<B>%f</B>
|
|
|
|
,
|
|
<B>%e</B>
|
|
|
|
, and
|
|
<B>%E</B>
|
|
|
|
conversions. For instance,
|
|
<B>%.4f</B>
|
|
|
|
prints a
|
|
<B>float</B>
|
|
|
|
with
|
|
4 fractional digits.
|
|
<P>
|
|
The integer in a
|
|
<B>width</B>
|
|
|
|
or
|
|
<B>precision</B>
|
|
|
|
can also be specified as
|
|
<B>*</B>
|
|
|
|
, in which case an extra integer argument is taken to specify
|
|
the corresponding
|
|
<B>width</B>
|
|
|
|
or
|
|
<B>precision</B>
|
|
|
|
. This integer argument
|
|
precedes immediately the argument to print.
|
|
For instance,
|
|
<B>%.*f</B>
|
|
|
|
prints a
|
|
<B>float</B>
|
|
|
|
with as many fractional
|
|
digits as the value of the argument given before the float.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val printf </I>
|
|
|
|
:
|
|
<B>('a, out_channel, unit) format -> 'a</B>
|
|
|
|
<P>
|
|
Same as
|
|
<B>Printf.fprintf</B>
|
|
|
|
, but output on
|
|
<B>stdout</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val eprintf </I>
|
|
|
|
:
|
|
<B>('a, out_channel, unit) format -> 'a</B>
|
|
|
|
<P>
|
|
Same as
|
|
<B>Printf.fprintf</B>
|
|
|
|
, but output on
|
|
<B>stderr</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val sprintf </I>
|
|
|
|
:
|
|
<B>('a, unit, string) format -> 'a</B>
|
|
|
|
<P>
|
|
Same as
|
|
<B>Printf.fprintf</B>
|
|
|
|
, but instead of printing on an output channel,
|
|
return a string containing the result of formatting the arguments.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val bprintf </I>
|
|
|
|
:
|
|
<B>Buffer.t -> ('a, Buffer.t, unit) format -> 'a</B>
|
|
|
|
<P>
|
|
Same as
|
|
<B>Printf.fprintf</B>
|
|
|
|
, but instead of printing on an output channel,
|
|
append the formatted arguments to the given extensible buffer
|
|
(see module
|
|
<B>Buffer</B>
|
|
|
|
).
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val ifprintf </I>
|
|
|
|
:
|
|
<B>'b -> ('a, 'b, 'c, unit) format4 -> 'a</B>
|
|
|
|
<P>
|
|
Same as
|
|
<B>Printf.fprintf</B>
|
|
|
|
, but does not print anything.
|
|
Useful to ignore some material when conditionally printing.
|
|
<P>
|
|
<P>
|
|
<B>Since</B>
|
|
|
|
3.10.0
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
|
|
Formatted output functions with continuations.
|
|
<P>
|
|
|
|
<P>
|
|
<I>val kfprintf </I>
|
|
|
|
:
|
|
<B>(out_channel -> 'd) -></B>
|
|
|
|
<B>out_channel -> ('a, out_channel, unit, 'd) format4 -> 'a</B>
|
|
|
|
<P>
|
|
Same as
|
|
<B>fprintf</B>
|
|
|
|
, but instead of returning immediately,
|
|
passes the out channel to its first argument at the end of printing.
|
|
<P>
|
|
<P>
|
|
<B>Since</B>
|
|
|
|
3.09.0
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val ikfprintf </I>
|
|
|
|
:
|
|
<B>('b -> 'd) -> 'b -> ('a, 'b, 'c, 'd) format4 -> 'a</B>
|
|
|
|
<P>
|
|
Same as
|
|
<B>kfprintf</B>
|
|
|
|
above, but does not print anything.
|
|
Useful to ignore some material when conditionally printing.
|
|
<P>
|
|
<P>
|
|
<B>Since</B>
|
|
|
|
4.01.0
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val ksprintf </I>
|
|
|
|
:
|
|
<B>(string -> 'd) -> ('a, unit, string, 'd) format4 -> 'a</B>
|
|
|
|
<P>
|
|
Same as
|
|
<B>sprintf</B>
|
|
|
|
above, but instead of returning the string,
|
|
passes it to the first argument.
|
|
<P>
|
|
<P>
|
|
<B>Since</B>
|
|
|
|
3.09.0
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val kbprintf </I>
|
|
|
|
:
|
|
<B>(Buffer.t -> 'd) -></B>
|
|
|
|
<B>Buffer.t -> ('a, Buffer.t, unit, 'd) format4 -> 'a</B>
|
|
|
|
<P>
|
|
Same as
|
|
<B>bprintf</B>
|
|
|
|
, but instead of returning immediately,
|
|
passes the buffer to its first argument at the end of printing.
|
|
<P>
|
|
<P>
|
|
<B>Since</B>
|
|
|
|
3.10.0
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
|
|
Deprecated
|
|
<P>
|
|
|
|
<P>
|
|
<I>val kprintf </I>
|
|
|
|
:
|
|
<B>(string -> 'b) -> ('a, unit, string, 'b) format4 -> 'a</B>
|
|
|
|
<P>
|
|
A deprecated synonym for
|
|
<B>ksprintf</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
|
|
<HR>
|
|
<A NAME="index"> </A><H2>Index</H2>
|
|
<DL>
|
|
<DT id="1"><A HREF="#lbAB">NAME</A><DD>
|
|
<DT id="2"><A HREF="#lbAC">Module</A><DD>
|
|
<DT id="3"><A HREF="#lbAD">Documentation</A><DD>
|
|
</DL>
|
|
<HR>
|
|
This document was created by
|
|
<A HREF="/cgi-bin/man/man2html">man2html</A>,
|
|
using the manual pages.<BR>
|
|
Time: 00:05:57 GMT, March 31, 2021
|
|
</BODY>
|
|
</HTML>
|